replace snprintf with strlcpy
authorBruce Richardson <bruce.richardson@intel.com>
Wed, 3 Apr 2019 14:45:05 +0000 (15:45 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Thu, 4 Apr 2019 20:46:05 +0000 (22:46 +0200)
Do a global replace of snprintf(..."%s",...) with strlcpy, adding in the
rte_string_fns.h header if needed.  The function changes in this patch were
auto-generated via command:

  spatch --sp-file devtools/cocci/strlcpy.cocci --dir . --in-place

and then the files edited using awk to add in the missing header:

  gawk -i inplace '/include <rte_/ && ! seen { \
   print "#include <rte_string_fns.h>"; seen=1} {print}'

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
53 files changed:
app/test-acl/main.c
app/test-eventdev/evt_options.c
app/test-pmd/cmdline_flow.c
app/test/test_table_acl.c
drivers/bus/dpaa/base/fman/of.c
drivers/bus/pci/linux/pci_uio.c
drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops.c
drivers/crypto/ccp/rte_ccp_pmd.c
drivers/crypto/scheduler/rte_cryptodev_scheduler.c
drivers/event/opdl/opdl_ring.c
drivers/net/af_packet/rte_eth_af_packet.c
drivers/net/ark/ark_pktchkr.c
drivers/net/ark/ark_pktgen.c
drivers/net/atlantic/atl_ethdev.c
drivers/net/bnx2x/bnx2x_ethdev.c
drivers/net/bnxt/bnxt_stats.c
drivers/net/dpaa/dpaa_ethdev.c
drivers/net/e1000/igb_ethdev.c
drivers/net/ena/ena_ethdev.c
drivers/net/failsafe/failsafe_eal.c
drivers/net/i40e/rte_pmd_i40e.c
drivers/net/ice/ice_ethdev.c
drivers/net/ixgbe/ixgbe_ethdev.c
drivers/net/kni/rte_eth_kni.c
drivers/net/liquidio/lio_ethdev.c
drivers/net/mvneta/mvneta_ethdev.c
drivers/net/mvpp2/mrvl_ethdev.c
drivers/net/qede/qede_ethdev.c
drivers/net/virtio/virtio_user/vhost_user.c
drivers/net/virtio/virtio_user/virtio_user_dev.c
examples/ethtool/lib/rte_ethtool.c
examples/l2fwd-crypto/main.c
examples/vm_power_manager/channel_manager.c
examples/vm_power_manager/channel_monitor.c
lib/librte_acl/rte_acl.c
lib/librte_bbdev/rte_bbdev.c
lib/librte_cfgfile/rte_cfgfile.c
lib/librte_compressdev/rte_compressdev.c
lib/librte_compressdev/rte_compressdev_pmd.c
lib/librte_cryptodev/rte_cryptodev_pmd.c
lib/librte_eal/common/eal_common_options.c
lib/librte_efd/rte_efd.c
lib/librte_eventdev/rte_eventdev.c
lib/librte_flow_classify/rte_flow_classify.c
lib/librte_jobstats/rte_jobstats.c
lib/librte_latencystats/rte_latencystats.c
lib/librte_member/rte_member.c
lib/librte_mempool/rte_mempool_ops.c
lib/librte_power/power_acpi_cpufreq.c
lib/librte_power/power_pstate_cpufreq.c
lib/librte_rawdev/rte_rawdev.c
lib/librte_reorder/rte_reorder.c
lib/librte_stack/rte_stack.c

index 648525a..b801794 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright(c) 2010-2014 Intel Corporation
  */
 
+#include <rte_string_fns.h>
 #include <rte_acl.h>
 #include <getopt.h>
 #include <string.h>
@@ -928,7 +929,7 @@ print_usage(const char *prgname)
                n += rc;
        }
 
-       snprintf(buf + n, sizeof(buf) - n, "%s", acl_alg[i].name);
+       strlcpy(buf + n, acl_alg[i].name, sizeof(buf) - n);
 
        fprintf(stdout,
                PRINT_USAGE_START
index af5c08b..46c074f 100644 (file)
@@ -7,6 +7,7 @@
 #include <inttypes.h>
 #include <getopt.h>
 
+#include <rte_string_fns.h>
 #include <rte_common.h>
 #include <rte_eventdev.h>
 #include <rte_lcore.h>
@@ -120,7 +121,7 @@ evt_parse_timer_prod_type_burst(struct evt_options *opt,
 static int
 evt_parse_test_name(struct evt_options *opt, const char *arg)
 {
-       snprintf(opt->test_name, EVT_TEST_NAME_MAX_LEN, "%s", arg);
+       strlcpy(opt->test_name, arg, EVT_TEST_NAME_MAX_LEN);
        return 0;
 }
 
index 36659a6..1c83bc9 100644 (file)
@@ -13,6 +13,7 @@
 #include <arpa/inet.h>
 #include <sys/socket.h>
 
+#include <rte_string_fns.h>
 #include <rte_common.h>
 #include <rte_eth_ctrl.h>
 #include <rte_ethdev.h>
@@ -4694,7 +4695,7 @@ comp_boolean(struct context *ctx, const struct token *token,
        (void)token;
        for (i = 0; boolean_name[i]; ++i)
                if (buf && i == ent)
-                       return snprintf(buf, size, "%s", boolean_name[i]);
+                       return strlcpy(buf, boolean_name[i], size);
        if (buf)
                return -1;
        return i;
@@ -4711,8 +4712,8 @@ comp_action(struct context *ctx, const struct token *token,
        (void)token;
        for (i = 0; next_action[i]; ++i)
                if (buf && i == ent)
-                       return snprintf(buf, size, "%s",
-                                       token_list[next_action[i]].name);
+                       return strlcpy(buf, token_list[next_action[i]].name,
+                                      size);
        if (buf)
                return -1;
        return i;
@@ -4776,7 +4777,7 @@ comp_vc_action_rss_type(struct context *ctx, const struct token *token,
        if (!buf)
                return i + 1;
        if (ent < i)
-               return snprintf(buf, size, "%s", rss_type_table[ent].str);
+               return strlcpy(buf, rss_type_table[ent].str, size);
        if (ent == i)
                return snprintf(buf, size, "end");
        return -1;
@@ -4961,7 +4962,7 @@ cmd_flow_complete_get_elt(cmdline_parse_token_hdr_t *hdr, int index,
        if (index >= i)
                return -1;
        token = &token_list[list[index]];
-       snprintf(dst, size, "%s", token->name);
+       strlcpy(dst, token->name, size);
        /* Save index for cmd_flow_get_help(). */
        ctx->prev = list[index];
        return 0;
@@ -4978,7 +4979,7 @@ cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
        if (!size)
                return -1;
        /* Set token type and update global help with details. */
-       snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN"));
+       strlcpy(dst, (token->type ? token->type : "TOKEN"), size);
        if (token->help)
                cmd_flow.help_str = token->help;
        else
index 33e2f6e..22136a3 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright(c) 2010-2014 Intel Corporation
  */
 
+#include <rte_string_fns.h>
 #include <rte_hexdump.h>
 #include "test_table.h"
 #include "test_table_acl.h"
@@ -467,7 +468,7 @@ setup_acl_pipeline(void)
                        memset(&keys[n], 0, sizeof(struct rte_table_acl_rule_add_params));
                        key_array[n] = &keys[n];
 
-                       snprintf(line, sizeof(line), "%s", lines[n]);
+                       strlcpy(line, lines[n], sizeof(line));
                        printf("PARSING [%s]\n", line);
 
                        ret = parser(line, &keys[n]);
@@ -509,7 +510,7 @@ setup_acl_pipeline(void)
                        memset(&keys[n], 0, sizeof(struct rte_table_acl_rule_delete_params));
                        key_array[n] = &keys[n];
 
-                       snprintf(line, sizeof(line), "%s", lines[n]);
+                       strlcpy(line, lines[n], sizeof(line));
                        printf("PARSING [%s]\n", line);
 
                        ret = parse_cb_ipv4_rule_del(line, &keys[n]);
@@ -545,7 +546,7 @@ setup_acl_pipeline(void)
                parser = parse_cb_ipv4_rule;
 
                for (n = 1; n <= 5; n++) {
-                       snprintf(line, sizeof(line), "%s", lines[n-1]);
+                       strlcpy(line, lines[n - 1], sizeof(line));
                        printf("PARSING [%s]\n", line);
 
                        ret = parser(line, &rule_params);
@@ -571,7 +572,7 @@ setup_acl_pipeline(void)
 
                /* delete a few rules */
                for (n = 2; n <= 3; n++) {
-                       snprintf(line, sizeof(line), "%s", lines[n-1]);
+                       strlcpy(line, lines[n - 1], sizeof(line));
                        printf("PARSING [%s]\n", line);
 
                        ret = parser(line, &rule_params);
@@ -598,7 +599,7 @@ setup_acl_pipeline(void)
 
                /* Try to add duplicates */
                for (n = 1; n <= 5; n++) {
-                       snprintf(line, sizeof(line), "%s", lines[n-1]);
+                       strlcpy(line, lines[n - 1], sizeof(line));
                        printf("PARSING [%s]\n", line);
 
                        ret = parser(line, &rule_params);
index a7f3174..1e97be5 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include <of.h>
+#include <rte_string_fns.h>
 #include <rte_dpaa_logs.h>
 
 static int alive;
@@ -60,7 +61,7 @@ process_file(struct dirent *dent, struct dt_dir *parent)
                return;
        }
        f->node.is_file = 1;
-       snprintf(f->node.node.name, NAME_MAX, "%s", dent->d_name);
+       strlcpy(f->node.node.name, dent->d_name, NAME_MAX);
        snprintf(f->node.node.full_name, PATH_MAX, "%s/%s",
                 parent->node.node.full_name, dent->d_name);
        f->parent = parent;
@@ -117,8 +118,8 @@ iterate_dir(struct dirent **d, int num, struct dt_dir *dt)
                                perror("malloc");
                                return -ENOMEM;
                        }
-                       snprintf(subdir->node.node.name, NAME_MAX, "%s",
-                                d[loop]->d_name);
+                       strlcpy(subdir->node.node.name, d[loop]->d_name,
+                               NAME_MAX);
                        snprintf(subdir->node.node.full_name, PATH_MAX,
                                 "%s/%s", dt->node.node.full_name,
                                 d[loop]->d_name);
index 09ecbb7..65f4896 100644 (file)
@@ -16,6 +16,7 @@
 #include <sys/io.h>
 #endif
 
+#include <rte_string_fns.h>
 #include <rte_log.h>
 #include <rte_pci.h>
 #include <rte_bus_pci.h>
@@ -268,7 +269,7 @@ pci_uio_alloc_resource(struct rte_pci_device *dev,
                goto error;
        }
 
-       snprintf((*uio_res)->path, sizeof((*uio_res)->path), "%s", devname);
+       strlcpy((*uio_res)->path, devname, sizeof((*uio_res)->path));
        memcpy(&(*uio_res)->pci_addr, &dev->addr, sizeof((*uio_res)->pci_addr));
 
        return 0;
index 3a8374e..8d15b99 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <string.h>
 
+#include <rte_string_fns.h>
 #include <rte_common.h>
 #include <rte_malloc.h>
 #include <rte_cryptodev_pmd.h>
@@ -614,7 +615,7 @@ aesni_mb_pmd_qp_create_processed_ops_ring(struct aesni_mb_qp *qp,
        struct rte_ring *r;
        char ring_name[RTE_CRYPTODEV_NAME_MAX_LEN];
 
-       unsigned int n = snprintf(ring_name, sizeof(ring_name), "%s", qp->name);
+       unsigned int n = strlcpy(ring_name, qp->name, sizeof(ring_name));
 
        if (n >= sizeof(ring_name))
                return NULL;
index b4bb552..4810d79 100644 (file)
@@ -2,6 +2,7 @@
  *   Copyright(c) 2018 Advanced Micro Devices, Inc. All rights reserved.
  */
 
+#include <rte_string_fns.h>
 #include <rte_bus_pci.h>
 #include <rte_bus_vdev.h>
 #include <rte_common.h>
@@ -298,9 +299,8 @@ cryptodev_ccp_create(const char *name,
        uint8_t cryptodev_cnt = 0;
 
        if (init_params->def_p.name[0] == '\0')
-               snprintf(init_params->def_p.name,
-                        sizeof(init_params->def_p.name),
-                        "%s", name);
+               strlcpy(init_params->def_p.name, name,
+                       sizeof(init_params->def_p.name));
 
        dev = rte_cryptodev_pmd_create(init_params->def_p.name,
                                       &vdev->device,
index a214286..1fef88f 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright(c) 2017 Intel Corporation
  */
+#include <rte_string_fns.h>
 #include <rte_reorder.h>
 #include <rte_cryptodev.h>
 #include <rte_cryptodev_pmd.h>
@@ -443,8 +444,7 @@ rte_cryptodev_scheduler_load_user_scheduler(uint8_t scheduler_id,
                                RTE_CRYPTODEV_NAME_MAX_LEN);
                return -EINVAL;
        }
-       snprintf(sched_ctx->name, sizeof(sched_ctx->name), "%s",
-                       scheduler->name);
+       strlcpy(sched_ctx->name, scheduler->name, sizeof(sched_ctx->name));
 
        if (strlen(scheduler->description) >
                        RTE_CRYPTODEV_SCHEDULER_DESC_MAX_LEN - 1) {
@@ -453,8 +453,8 @@ rte_cryptodev_scheduler_load_user_scheduler(uint8_t scheduler_id,
                                RTE_CRYPTODEV_SCHEDULER_DESC_MAX_LEN - 1);
                return -EINVAL;
        }
-       snprintf(sched_ctx->description, sizeof(sched_ctx->description), "%s",
-                       scheduler->description);
+       strlcpy(sched_ctx->description, scheduler->description,
+               sizeof(sched_ctx->description));
 
        /* load scheduler instance operations functions */
        sched_ctx->ops.config_queue_pair = scheduler->ops->config_queue_pair;
index 8aca481..e988f1c 100644 (file)
@@ -7,6 +7,7 @@
 #include <stdint.h>
 #include <stdio.h>
 
+#include <rte_string_fns.h>
 #include <rte_branch_prediction.h>
 #include <rte_debug.h>
 #include <rte_lcore.h>
@@ -944,7 +945,7 @@ opdl_ring_create(const char *name, uint32_t num_slots, uint32_t slot_size,
 
        /* Initialise opdl_ring queue */
        memset(t, 0, sizeof(*t));
-       snprintf(t->name, sizeof(t->name), "%s", name);
+       strlcpy(t->name, name, sizeof(t->name));
        t->socket = socket;
        t->num_slots = num_slots;
        t->mask = num_slots - 1;
index 264cfc0..99e13fe 100644 (file)
@@ -6,6 +6,7 @@
  * All rights reserved.
  */
 
+#include <rte_string_fns.h>
 #include <rte_mbuf.h>
 #include <rte_ethdev_driver.h>
 #include <rte_ethdev_vdev.h>
@@ -442,7 +443,7 @@ eth_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
        if (s < 0)
                return -EINVAL;
 
-       snprintf(ifr.ifr_name, IFNAMSIZ, "%s", internals->if_name);
+       strlcpy(ifr.ifr_name, internals->if_name, IFNAMSIZ);
        ret = ioctl(s, SIOCSIFMTU, &ifr);
        close(s);
 
@@ -462,7 +463,7 @@ eth_dev_change_flags(char *if_name, uint32_t flags, uint32_t mask)
        if (s < 0)
                return;
 
-       snprintf(ifr.ifr_name, IFNAMSIZ, "%s", if_name);
+       strlcpy(ifr.ifr_name, if_name, IFNAMSIZ);
        if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0)
                goto out;
        ifr.ifr_flags &= mask;
index c21003a..ef861ee 100644 (file)
@@ -7,6 +7,7 @@
 #include <locale.h>
 #include <unistd.h>
 
+#include <rte_string_fns.h>
 #include <rte_ethdev_driver.h>
 #include <rte_malloc.h>
 
@@ -347,7 +348,7 @@ set_arg(char *arg, char *val)
                        o->v.INT = atoll(val);
                        break;
                case OTSTRING:
-                       snprintf(o->v.STR, ARK_MAX_STR_LEN, "%s", val);
+                       strlcpy(o->v.STR, val, ARK_MAX_STR_LEN);
                        break;
                }
                return 1;
index 2a2b428..2cae252 100644 (file)
@@ -7,6 +7,7 @@
 #include <locale.h>
 #include <unistd.h>
 
+#include <rte_string_fns.h>
 #include <rte_eal.h>
 
 #include <rte_ethdev_driver.h>
@@ -329,7 +330,7 @@ pmd_set_arg(char *arg, char *val)
                        o->v.INT = atoll(val);
                        break;
                case OTSTRING:
-                       snprintf(o->v.STR, ARK_MAX_STR_LEN, "%s", val);
+                       strlcpy(o->v.STR, val, ARK_MAX_STR_LEN);
                        break;
                }
                return 1;
index 5c62d13..8327863 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright(c) 2018 Aquantia Corporation
  */
 
+#include <rte_string_fns.h>
 #include <rte_ethdev_pci.h>
 
 #include "atl_ethdev.h"
@@ -755,8 +756,8 @@ atl_dev_xstats_get_names(struct rte_eth_dev *dev __rte_unused,
                return RTE_DIM(atl_xstats_tbl);
 
        for (i = 0; i < size && i < RTE_DIM(atl_xstats_tbl); i++)
-               snprintf(xstats_names[i].name, RTE_ETH_XSTATS_NAME_SIZE, "%s",
-                       atl_xstats_tbl[i].name);
+               strlcpy(xstats_names[i].name, atl_xstats_tbl[i].name,
+                       RTE_ETH_XSTATS_NAME_SIZE);
 
        return i;
 }
index cc7816d..1f2eb92 100644 (file)
@@ -8,6 +8,7 @@
 #include "bnx2x.h"
 #include "bnx2x_rxtx.h"
 
+#include <rte_string_fns.h>
 #include <rte_dev.h>
 #include <rte_ethdev_pci.h>
 #include <rte_alarm.h>
@@ -445,10 +446,9 @@ bnx2x_get_xstats_names(__rte_unused struct rte_eth_dev *dev,
 
        if (xstats_names != NULL)
                for (i = 0; i < stat_cnt; i++)
-                       snprintf(xstats_names[i].name,
-                               sizeof(xstats_names[i].name),
-                               "%s",
-                               bnx2x_xstats_strings[i].name);
+                       strlcpy(xstats_names[i].name,
+                               bnx2x_xstats_strings[i].name,
+                               sizeof(xstats_names[i].name));
 
        return stat_cnt;
 }
index c16bf99..cae3b9e 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <inttypes.h>
 
+#include <rte_string_fns.h>
 #include <rte_byteorder.h>
 
 #include "bnxt.h"
@@ -491,41 +492,36 @@ int bnxt_dev_xstats_get_names_op(__rte_unused struct rte_eth_dev *eth_dev,
                count = 0;
 
                for (i = 0; i < RTE_DIM(bnxt_rx_stats_strings); i++) {
-                       snprintf(xstats_names[count].name,
-                               sizeof(xstats_names[count].name),
-                               "%s",
-                               bnxt_rx_stats_strings[i].name);
+                       strlcpy(xstats_names[count].name,
+                               bnxt_rx_stats_strings[i].name,
+                               sizeof(xstats_names[count].name));
                        count++;
                }
 
                for (i = 0; i < RTE_DIM(bnxt_tx_stats_strings); i++) {
-                       snprintf(xstats_names[count].name,
-                               sizeof(xstats_names[count].name),
-                               "%s",
-                               bnxt_tx_stats_strings[i].name);
+                       strlcpy(xstats_names[count].name,
+                               bnxt_tx_stats_strings[i].name,
+                               sizeof(xstats_names[count].name));
                        count++;
                }
 
-               snprintf(xstats_names[count].name,
-                               sizeof(xstats_names[count].name),
-                               "%s",
-                               bnxt_func_stats_strings[4].name);
+               strlcpy(xstats_names[count].name,
+                       bnxt_func_stats_strings[4].name,
+                       sizeof(xstats_names[count].name));
                count++;
 
                for (i = 0; i < RTE_DIM(bnxt_rx_ext_stats_strings); i++) {
-                       snprintf(xstats_names[count].name,
-                                sizeof(xstats_names[count].name),
-                                "%s",
-                                bnxt_rx_ext_stats_strings[i].name);
+                       strlcpy(xstats_names[count].name,
+                               bnxt_rx_ext_stats_strings[i].name,
+                               sizeof(xstats_names[count].name));
 
                        count++;
                }
 
                for (i = 0; i < RTE_DIM(bnxt_tx_ext_stats_strings); i++) {
-                       snprintf(xstats_names[count].name,
-                                sizeof(xstats_names[count].name),
-                                "%s",
-                                bnxt_tx_ext_stats_strings[i].name);
+                       strlcpy(xstats_names[count].name,
+                               bnxt_tx_ext_stats_strings[i].name,
+                               sizeof(xstats_names[count].name));
 
                        count++;
                }
index b1fac8f..2e043fe 100644 (file)
@@ -15,6 +15,7 @@
 #include <sys/types.h>
 #include <sys/syscall.h>
 
+#include <rte_string_fns.h>
 #include <rte_byteorder.h>
 #include <rte_common.h>
 #include <rte_interrupts.h>
@@ -439,10 +440,9 @@ dpaa_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
 
        if (xstats_names != NULL)
                for (i = 0; i < stat_cnt; i++)
-                       snprintf(xstats_names[i].name,
-                                sizeof(xstats_names[i].name),
-                                "%s",
-                                dpaa_xstats_strings[i].name);
+                       strlcpy(xstats_names[i].name,
+                               dpaa_xstats_strings[i].name,
+                               sizeof(xstats_names[i].name));
 
        return stat_cnt;
 }
index b897e8a..d3a8f5b 100644 (file)
@@ -8,6 +8,7 @@
 #include <stdint.h>
 #include <stdarg.h>
 
+#include <rte_string_fns.h>
 #include <rte_common.h>
 #include <rte_interrupts.h>
 #include <rte_byteorder.h>
@@ -1904,8 +1905,8 @@ static int eth_igb_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
        /* Note: limit checked in rte_eth_xstats_names() */
 
        for (i = 0; i < IGB_NB_XSTATS; i++) {
-               snprintf(xstats_names[i].name, sizeof(xstats_names[i].name),
-                        "%s", rte_igb_stats_strings[i].name);
+               strlcpy(xstats_names[i].name, rte_igb_stats_strings[i].name,
+                       sizeof(xstats_names[i].name));
        }
 
        return IGB_NB_XSTATS;
@@ -1922,9 +1923,9 @@ static int eth_igb_xstats_get_names_by_id(struct rte_eth_dev *dev,
                        return IGB_NB_XSTATS;
 
                for (i = 0; i < IGB_NB_XSTATS; i++)
-                       snprintf(xstats_names[i].name,
-                                       sizeof(xstats_names[i].name),
-                                       "%s", rte_igb_stats_strings[i].name);
+                       strlcpy(xstats_names[i].name,
+                               rte_igb_stats_strings[i].name,
+                               sizeof(xstats_names[i].name));
 
                return IGB_NB_XSTATS;
 
@@ -2071,9 +2072,9 @@ static int eth_igbvf_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
 
        if (xstats_names != NULL)
                for (i = 0; i < IGBVF_NB_XSTATS; i++) {
-                       snprintf(xstats_names[i].name,
-                               sizeof(xstats_names[i].name), "%s",
-                               rte_igbvf_stats_strings[i].name);
+                       strlcpy(xstats_names[i].name,
+                               rte_igbvf_stats_strings[i].name,
+                               sizeof(xstats_names[i].name));
                }
        return IGBVF_NB_XSTATS;
 }
index 08b1ab1..a55b4a7 100644 (file)
@@ -31,6 +31,7 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
+#include <rte_string_fns.h>
 #include <rte_ether.h>
 #include <rte_ethdev_driver.h>
 #include <rte_ethdev_pci.h>
@@ -421,13 +422,11 @@ static void ena_config_host_info(struct ena_com_dev *ena_dev)
 
        host_info->os_type = ENA_ADMIN_OS_DPDK;
        host_info->kernel_ver = RTE_VERSION;
-       snprintf((char *)host_info->kernel_ver_str,
-                sizeof(host_info->kernel_ver_str),
-                "%s", rte_version());
+       strlcpy((char *)host_info->kernel_ver_str, rte_version(),
+               sizeof(host_info->kernel_ver_str));
        host_info->os_dist = RTE_VERSION;
-       snprintf((char *)host_info->os_dist_str,
-                sizeof(host_info->os_dist_str),
-                "%s", rte_version());
+       strlcpy((char *)host_info->os_dist_str, rte_version(),
+               sizeof(host_info->os_dist_str));
        host_info->driver_version =
                (DRV_MODULE_VER_MAJOR) |
                (DRV_MODULE_VER_MINOR << ENA_ADMIN_HOST_INFO_MINOR_SHIFT) |
index 74fd8e9..820a915 100644 (file)
@@ -3,6 +3,7 @@
  * Copyright 2017 Mellanox Technologies, Ltd
  */
 
+#include <rte_string_fns.h>
 #include <rte_malloc.h>
 
 #include "failsafe_private.h"
@@ -84,8 +85,9 @@ fs_bus_init(struct rte_eth_dev *dev)
                                snprintf(devstr, sizeof(devstr), "%s,%s",
                                         probed_da->name, probed_da->args);
                        else
-                               snprintf(devstr, sizeof(devstr), "%s",
-                                        rte_eth_devices[pid].device->name);
+                               strlcpy(devstr,
+                                       rte_eth_devices[pid].device->name,
+                                       sizeof(devstr));
                        ret = rte_devargs_parse(da, devstr);
                        if (ret) {
                                ERROR("Probed devargs parsing failed with code"
index c49c872..7ae78e4 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright(c) 2010-2017 Intel Corporation
  */
 
+#include <rte_string_fns.h>
 #include <rte_malloc.h>
 #include <rte_tailq.h>
 
@@ -1983,8 +1984,8 @@ int rte_pmd_i40e_get_ddp_info(uint8_t *pkg_buff, uint32_t pkg_size,
                tlv = (struct i40e_profile_tlv_section_record *)&proto[1];
                for (i = j = 0; i < nb_rec; j++) {
                        pinfo[j].proto_id = tlv->data[0];
-                       snprintf(pinfo[j].name, I40E_DDP_NAME_SIZE, "%s",
-                                (const char *)&tlv->data[1]);
+                       strlcpy(pinfo[j].name, (const char *)&tlv->data[1],
+                               I40E_DDP_NAME_SIZE);
                        i += tlv->len;
                        tlv = &tlv[tlv->len];
                }
index 1482ced..a06ebda 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright(c) 2018 Intel Corporation
  */
 
+#include <rte_string_fns.h>
 #include <rte_ethdev_pci.h>
 
 #include <stdio.h>
@@ -3437,17 +3438,15 @@ static int ice_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
 
        /* Get stats from ice_eth_stats struct */
        for (i = 0; i < ICE_NB_ETH_XSTATS; i++) {
-               snprintf(xstats_names[count].name,
-                        sizeof(xstats_names[count].name),
-                        "%s", ice_stats_strings[i].name);
+               strlcpy(xstats_names[count].name, ice_stats_strings[i].name,
+                       sizeof(xstats_names[count].name));
                count++;
        }
 
        /* Get individiual stats from ice_hw_port struct */
        for (i = 0; i < ICE_NB_HW_PORT_XSTATS; i++) {
-               snprintf(xstats_names[count].name,
-                        sizeof(xstats_names[count].name),
-                        "%s", ice_hw_port_strings[i].name);
+               strlcpy(xstats_names[count].name, ice_hw_port_strings[i].name,
+                       sizeof(xstats_names[count].name));
                count++;
        }
 
index feec856..b1be0c8 100644 (file)
@@ -11,6 +11,7 @@
 #include <stdarg.h>
 #include <inttypes.h>
 #include <netinet/in.h>
+#include <rte_string_fns.h>
 #include <rte_byteorder.h>
 #include <rte_common.h>
 #include <rte_cycles.h>
@@ -3293,19 +3294,17 @@ static int ixgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
 
                /* Extended stats from ixgbe_hw_stats */
                for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
-                       snprintf(xstats_names[count].name,
-                               sizeof(xstats_names[count].name),
-                               "%s",
-                               rte_ixgbe_stats_strings[i].name);
+                       strlcpy(xstats_names[count].name,
+                               rte_ixgbe_stats_strings[i].name,
+                               sizeof(xstats_names[count].name));
                        count++;
                }
 
                /* MACsec Stats */
                for (i = 0; i < IXGBE_NB_MACSEC_STATS; i++) {
-                       snprintf(xstats_names[count].name,
-                               sizeof(xstats_names[count].name),
-                               "%s",
-                               rte_ixgbe_macsec_strings[i].name);
+                       strlcpy(xstats_names[count].name,
+                               rte_ixgbe_macsec_strings[i].name,
+                               sizeof(xstats_names[count].name));
                        count++;
                }
 
@@ -3353,19 +3352,17 @@ static int ixgbe_dev_xstats_get_names_by_id(
 
                        /* Extended stats from ixgbe_hw_stats */
                        for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
-                               snprintf(xstats_names[count].name,
-                                       sizeof(xstats_names[count].name),
-                                       "%s",
-                                       rte_ixgbe_stats_strings[i].name);
+                               strlcpy(xstats_names[count].name,
+                                       rte_ixgbe_stats_strings[i].name,
+                                       sizeof(xstats_names[count].name));
                                count++;
                        }
 
                        /* MACsec Stats */
                        for (i = 0; i < IXGBE_NB_MACSEC_STATS; i++) {
-                               snprintf(xstats_names[count].name,
-                                       sizeof(xstats_names[count].name),
-                                       "%s",
-                                       rte_ixgbe_macsec_strings[i].name);
+                               strlcpy(xstats_names[count].name,
+                                       rte_ixgbe_macsec_strings[i].name,
+                                       sizeof(xstats_names[count].name));
                                count++;
                        }
 
@@ -3422,9 +3419,9 @@ static int ixgbevf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
 
        if (xstats_names != NULL)
                for (i = 0; i < IXGBEVF_NB_XSTATS; i++)
-                       snprintf(xstats_names[i].name,
-                               sizeof(xstats_names[i].name),
-                               "%s", rte_ixgbevf_stats_strings[i].name);
+                       strlcpy(xstats_names[i].name,
+                               rte_ixgbevf_stats_strings[i].name,
+                               sizeof(xstats_names[i].name));
        return IXGBEVF_NB_XSTATS;
 }
 
index 5e02224..89f4473 100644 (file)
@@ -6,6 +6,7 @@
 #include <pthread.h>
 #include <unistd.h>
 
+#include <rte_string_fns.h>
 #include <rte_ethdev_driver.h>
 #include <rte_ethdev_vdev.h>
 #include <rte_kni.h>
@@ -126,7 +127,7 @@ eth_kni_start(struct rte_eth_dev *dev)
        const char *name = dev->device->name + 4; /* remove net_ */
 
        mb_pool = internals->rx_queues[0].mb_pool;
-       snprintf(conf.name, RTE_KNI_NAMESIZE, "%s", name);
+       strlcpy(conf.name, name, RTE_KNI_NAMESIZE);
        conf.force_bind = 0;
        conf.group_id = port_id;
        conf.mbuf_size =
index d13ab06..c9cabd6 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright(c) 2017 Cavium, Inc
  */
 
+#include <rte_string_fns.h>
 #include <rte_ethdev_driver.h>
 #include <rte_ethdev_pci.h>
 #include <rte_cycles.h>
@@ -1781,8 +1782,8 @@ lio_dev_configure(struct rte_eth_dev *eth_dev)
                goto nic_config_fail;
        }
 
-       snprintf(lio_dev->firmware_version, LIO_FW_VERSION_LENGTH, "%s",
-                resp->cfg_info.lio_firmware_version);
+       strlcpy(lio_dev->firmware_version,
+               resp->cfg_info.lio_firmware_version, LIO_FW_VERSION_LENGTH);
 
        lio_swap_8B_data((uint64_t *)(&resp->cfg_info),
                         sizeof(struct octeon_if_cfg_info) >> 3);
index 2d76664..8923a16 100644 (file)
@@ -4,6 +4,7 @@
  * All rights reserved.
  */
 
+#include <rte_string_fns.h>
 #include <rte_ethdev_driver.h>
 #include <rte_kvargs.h>
 #include <rte_bus_vdev.h>
@@ -347,7 +348,7 @@ mvneta_dev_start(struct rte_eth_dev *dev)
        if (priv->ppio)
                return mvneta_dev_set_link_up(dev);
 
-       snprintf(match, sizeof(match), "%s", dev->data->name);
+       strlcpy(match, dev->data->name, sizeof(match));
        priv->ppio_params.match = match;
        priv->ppio_params.inqs_params.mtu = dev->data->mtu;
 
index ab4c14e..ce52f09 100644 (file)
@@ -4,6 +4,7 @@
  * All rights reserved.
  */
 
+#include <rte_string_fns.h>
 #include <rte_ethdev_driver.h>
 #include <rte_kvargs.h>
 #include <rte_log.h>
@@ -1388,8 +1389,8 @@ mrvl_xstats_get_names(struct rte_eth_dev *dev __rte_unused,
                return RTE_DIM(mrvl_xstats_tbl);
 
        for (i = 0; i < size && i < RTE_DIM(mrvl_xstats_tbl); i++)
-               snprintf(xstats_names[i].name, RTE_ETH_XSTATS_NAME_SIZE, "%s",
-                        mrvl_xstats_tbl[i].name);
+               strlcpy(xstats_names[i].name, mrvl_xstats_tbl[i].name,
+                       RTE_ETH_XSTATS_NAME_SIZE);
 
        return size;
 }
index 0b2f305..b2fd2fd 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include "qede_ethdev.h"
+#include <rte_string_fns.h>
 #include <rte_alarm.h>
 #include <rte_version.h>
 #include <rte_kvargs.h>
@@ -1591,27 +1592,24 @@ qede_get_xstats_names(struct rte_eth_dev *dev,
 
        if (xstats_names != NULL) {
                for (i = 0; i < RTE_DIM(qede_xstats_strings); i++) {
-                       snprintf(xstats_names[stat_idx].name,
-                               sizeof(xstats_names[stat_idx].name),
-                               "%s",
-                               qede_xstats_strings[i].name);
+                       strlcpy(xstats_names[stat_idx].name,
+                               qede_xstats_strings[i].name,
+                               sizeof(xstats_names[stat_idx].name));
                        stat_idx++;
                }
 
                if (ECORE_IS_BB(edev)) {
                        for (i = 0; i < RTE_DIM(qede_bb_xstats_strings); i++) {
-                               snprintf(xstats_names[stat_idx].name,
-                                       sizeof(xstats_names[stat_idx].name),
-                                       "%s",
-                                       qede_bb_xstats_strings[i].name);
+                               strlcpy(xstats_names[stat_idx].name,
+                                       qede_bb_xstats_strings[i].name,
+                                       sizeof(xstats_names[stat_idx].name));
                                stat_idx++;
                        }
                } else {
                        for (i = 0; i < RTE_DIM(qede_ah_xstats_strings); i++) {
-                               snprintf(xstats_names[stat_idx].name,
-                                       sizeof(xstats_names[stat_idx].name),
-                                       "%s",
-                                       qede_ah_xstats_strings[i].name);
+                               strlcpy(xstats_names[stat_idx].name,
+                                       qede_ah_xstats_strings[i].name,
+                                       sizeof(xstats_names[stat_idx].name));
                                stat_idx++;
                        }
                }
index 2c6eba0..827a48a 100644 (file)
@@ -11,6 +11,7 @@
 #include <string.h>
 #include <errno.h>
 
+#include <rte_string_fns.h>
 #include <rte_fbarray.h>
 #include <rte_eal_memconfig.h>
 
@@ -424,7 +425,7 @@ vhost_user_setup(struct virtio_user_dev *dev)
 
        memset(&un, 0, sizeof(un));
        un.sun_family = AF_UNIX;
-       snprintf(un.sun_path, sizeof(un.sun_path), "%s", dev->path);
+       strlcpy(un.sun_path, dev->path, sizeof(un.sun_path));
 
        if (dev->is_server) {
                dev->listenfd = fd;
index b004bc1..8e420bc 100644 (file)
@@ -13,6 +13,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
+#include <rte_string_fns.h>
 #include <rte_eal_memconfig.h>
 
 #include "vhost.h"
@@ -429,7 +430,7 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
                     int server, int mrg_rxbuf, int in_order, int packed_vq)
 {
        pthread_mutex_init(&dev->mutex, NULL);
-       snprintf(dev->path, PATH_MAX, "%s", path);
+       strlcpy(dev->path, path, PATH_MAX);
        dev->started = 0;
        dev->max_queue_pairs = queues;
        dev->queue_pairs = 1; /* mq disabled by default */
index e6a2e88..bf10139 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
+#include <rte_string_fns.h>
 #include <rte_version.h>
 #include <rte_ethdev.h>
 #include <rte_ether.h>
@@ -43,10 +44,9 @@ rte_ethtool_get_drvinfo(uint16_t port_id, struct ethtool_drvinfo *drvinfo)
        memset(&dev_info, 0, sizeof(dev_info));
        rte_eth_dev_info_get(port_id, &dev_info);
 
-       snprintf(drvinfo->driver, sizeof(drvinfo->driver), "%s",
-               dev_info.driver_name);
-       snprintf(drvinfo->version, sizeof(drvinfo->version), "%s",
-               rte_version());
+       strlcpy(drvinfo->driver, dev_info.driver_name,
+               sizeof(drvinfo->driver));
+       strlcpy(drvinfo->version, rte_version(), sizeof(drvinfo->version));
        /* TODO: replace bus_info by rte_devargs.name */
        if (dev_info.device)
                bus = rte_bus_find_by_device(dev_info.device);
index 9982f07..06517b4 100644 (file)
@@ -19,6 +19,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 
+#include <rte_string_fns.h>
 #include <rte_atomic.h>
 #include <rte_branch_prediction.h>
 #include <rte_common.h>
@@ -1199,8 +1200,7 @@ l2fwd_crypto_parse_args_long_options(struct l2fwd_crypto_options *options,
        if (strcmp(lgopts[option_index].name, "cdev_type") == 0) {
                retval = parse_cryptodev_type(&options->type, optarg);
                if (retval == 0)
-                       snprintf(options->string_type, MAX_STR_LEN,
-                               "%s", optarg);
+                       strlcpy(options->string_type, optarg, MAX_STR_LEN);
                return retval;
        }
 
index 09bfa5c..0187f79 100644 (file)
@@ -17,6 +17,7 @@
 #include <sys/socket.h>
 #include <sys/select.h>
 
+#include <rte_string_fns.h>
 #include <rte_malloc.h>
 #include <rte_memory.h>
 #include <rte_mempool.h>
@@ -415,7 +416,7 @@ add_all_channels(const char *vm_name)
                                !strncmp(dir->d_name, "..", 2))
                        continue;
 
-               snprintf(socket_name, sizeof(socket_name), "%s", dir->d_name);
+               strlcpy(socket_name, dir->d_name, sizeof(socket_name));
                remaining = socket_name;
                /* Extract vm_name from "<vm_name>.<channel_num>" */
                token = strsep(&remaining, ".");
@@ -562,8 +563,8 @@ add_host_channel(void)
                                "channel '%s'\n", socket_path);
                return 0;
        }
-       snprintf(chan_info->channel_path,
-                       sizeof(chan_info->channel_path), "%s", socket_path);
+       strlcpy(chan_info->channel_path, socket_path,
+               sizeof(chan_info->channel_path));
        if (setup_host_channel_info(&chan_info, 0) < 0) {
                rte_free(chan_info);
                return 0;
index 7892d75..74df0fe 100644 (file)
@@ -21,6 +21,7 @@
 #else
 #pragma message "Jansson dev libs unavailable, not including JSON parsing"
 #endif
+#include <rte_string_fns.h>
 #include <rte_log.h>
 #include <rte_memory.h>
 #include <rte_malloc.h>
@@ -161,7 +162,7 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt)
                        strcpy(pkt->vm_name, json_string_value(value));
                } else if (!strcmp(key, "command")) {
                        char command[32];
-                       snprintf(command, 32, "%s", json_string_value(value));
+                       strlcpy(command, json_string_value(value), 32);
                        if (!strcmp(command, "power")) {
                                pkt->command = CPU_POWER;
                        } else if (!strcmp(command, "create")) {
@@ -175,7 +176,7 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt)
                        }
                } else if (!strcmp(key, "policy_type")) {
                        char command[32];
-                       snprintf(command, 32, "%s", json_string_value(value));
+                       strlcpy(command, json_string_value(value), 32);
                        if (!strcmp(command, "TIME")) {
                                pkt->policy_to_use = TIME;
                        } else if (!strcmp(command, "TRAFFIC")) {
@@ -191,7 +192,7 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt)
                        }
                } else if (!strcmp(key, "workload")) {
                        char command[32];
-                       snprintf(command, 32, "%s", json_string_value(value));
+                       strlcpy(command, json_string_value(value), 32);
                        if (!strcmp(command, "HIGH")) {
                                pkt->workload = HIGH;
                        } else if (!strcmp(command, "MEDIUM")) {
@@ -237,8 +238,9 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt)
 
                        for (i = 0; i < size; i++) {
                                char mac[32];
-                               snprintf(mac, 32, "%s", json_string_value(
-                                               json_array_get(value, i)));
+                               strlcpy(mac,
+                                       json_string_value(json_array_get(value, i)),
+                                       32);
                                set_policy_mac(pkt, i, mac);
                        }
                        pkt->nb_mac_to_monitor = size;
@@ -250,7 +252,7 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt)
                                        (uint32_t)json_integer_value(value);
                } else if (!strcmp(key, "unit")) {
                        char unit[32];
-                       snprintf(unit, 32, "%s", json_string_value(value));
+                       strlcpy(unit, json_string_value(value), 32);
                        if (!strcmp(unit, "SCALE_UP")) {
                                pkt->unit = CPU_POWER_SCALE_UP;
                        } else if (!strcmp(unit, "SCALE_DOWN")) {
index db7d322..c436a9b 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright(c) 2010-2014 Intel Corporation
  */
 
+#include <rte_string_fns.h>
 #include <rte_acl.h>
 #include "acl.h"
 
@@ -249,7 +250,7 @@ rte_acl_create(const struct rte_acl_param *param)
                ctx->rule_sz = param->rule_size;
                ctx->socket_id = param->socket_id;
                ctx->alg = rte_acl_default_classify;
-               snprintf(ctx->name, sizeof(ctx->name), "%s", param->name);
+               strlcpy(ctx->name, param->name, sizeof(ctx->name));
 
                te->data = (void *) ctx;
 
index c4cc18d..a3ab5d9 100644 (file)
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <stdbool.h>
 
+#include <rte_string_fns.h>
 #include <rte_compat.h>
 #include <rte_common.h>
 #include <rte_errno.h>
@@ -214,7 +215,7 @@ rte_bbdev_allocate(const char *name)
        bbdev->data->dev_id = dev_id;
        bbdev->state = RTE_BBDEV_INITIALIZED;
 
-       ret = snprintf(bbdev->data->name, RTE_BBDEV_NAME_MAX_LEN, "%s", name);
+       ret = strlcpy(bbdev->data->name, name, RTE_BBDEV_NAME_MAX_LEN);
        if ((ret < 0) || (ret >= RTE_BBDEV_NAME_MAX_LEN)) {
                rte_bbdev_log(ERR, "Copying device name \"%s\" failed", name);
                return NULL;
index 7d8c941..6110dba 100644 (file)
@@ -7,6 +7,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <errno.h>
+#include <rte_string_fns.h>
 #include <rte_common.h>
 
 #include "rte_cfgfile.h"
@@ -113,9 +114,8 @@ _add_entry(struct rte_cfgfile_section *section, const char *entryname,
        struct rte_cfgfile_entry *curr_entry =
                                        &section->entries[section->num_entries];
 
-       snprintf(curr_entry->name, sizeof(curr_entry->name), "%s", entryname);
-       snprintf(curr_entry->value,
-                               sizeof(curr_entry->value), "%s", entryvalue);
+       strlcpy(curr_entry->name, entryname, sizeof(curr_entry->name));
+       strlcpy(curr_entry->value, entryvalue, sizeof(curr_entry->value));
        section->num_entries++;
 
        return 0;
@@ -341,8 +341,8 @@ rte_cfgfile_add_section(struct rte_cfgfile *cfg, const char *sectionname)
                cfg->allocated_sections += CFG_ALLOC_SECTION_BATCH;
        }
 
-       snprintf(cfg->sections[cfg->num_sections].name,
-                       sizeof(cfg->sections[0].name), "%s", sectionname);
+       strlcpy(cfg->sections[cfg->num_sections].name, sectionname,
+               sizeof(cfg->sections[0].name));
        cfg->sections[cfg->num_sections].num_entries = 0;
        cfg->num_sections++;
 
@@ -392,9 +392,8 @@ int rte_cfgfile_set_entry(struct rte_cfgfile *cfg, const char *sectionname,
 
        for (i = 0; i < curr_section->num_entries; i++)
                if (!strcmp(curr_section->entries[i].name, entryname)) {
-                       snprintf(curr_section->entries[i].value,
-                                       sizeof(curr_section->entries[i].value),
-                                                       "%s", entryvalue);
+                       strlcpy(curr_section->entries[i].value, entryvalue,
+                               sizeof(curr_section->entries[i].value));
                        return 0;
                }
        printf("Error - entry name doesn't exist\n");
@@ -468,8 +467,7 @@ rte_cfgfile_sections(struct rte_cfgfile *cfg, char *sections[],
        int i;
 
        for (i = 0; i < cfg->num_sections && i < max_sections; i++)
-               snprintf(sections[i], CFG_NAME_LEN, "%s",
-               cfg->sections[i].name);
+               strlcpy(sections[i], cfg->sections[i].name, CFG_NAME_LEN);
 
        return i;
 }
@@ -499,7 +497,7 @@ rte_cfgfile_section_num_entries_by_index(struct rte_cfgfile *cfg,
 
        const struct rte_cfgfile_section *sect = &(cfg->sections[index]);
 
-       snprintf(sectionname, CFG_NAME_LEN, "%s", sect->name);
+       strlcpy(sectionname, sect->name, CFG_NAME_LEN);
        return sect->num_entries;
 }
 int
@@ -526,7 +524,7 @@ rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg, int index,
        if (index < 0 || index >= cfg->num_sections)
                return -1;
        sect = &cfg->sections[index];
-       snprintf(sectionname, CFG_NAME_LEN, "%s", sect->name);
+       strlcpy(sectionname, sect->name, CFG_NAME_LEN);
        for (i = 0; i < max_entries && i < sect->num_entries; i++)
                entries[i] = sect->entries[i];
        return i;
index 338134b..afba584 100644 (file)
@@ -7,6 +7,7 @@
 #include <stdio.h>
 #include <inttypes.h>
 
+#include <rte_string_fns.h>
 #include <rte_malloc.h>
 #include <rte_eal.h>
 #include <rte_memzone.h>
@@ -252,8 +253,8 @@ rte_compressdev_pmd_allocate(const char *name, int socket_id)
 
                compressdev->data = compressdev_data;
 
-               snprintf(compressdev->data->name, RTE_COMPRESSDEV_NAME_MAX_LEN,
-                               "%s", name);
+               strlcpy(compressdev->data->name, name,
+                       RTE_COMPRESSDEV_NAME_MAX_LEN);
 
                compressdev->data->dev_id = dev_id;
                compressdev->data->socket_id = socket_id;
index 95beb26..cc51d69 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright(c) 2017-2018 Intel Corporation
  */
 
+#include <rte_string_fns.h>
 #include <rte_malloc.h>
 #include <rte_kvargs.h>
 #include <rte_eal.h>
@@ -21,7 +22,7 @@ rte_compressdev_pmd_parse_name_arg(const char *key __rte_unused,
        struct rte_compressdev_pmd_init_params *params = extra_args;
        int n;
 
-       n = snprintf(params->name, RTE_COMPRESSDEV_NAME_MAX_LEN, "%s", value);
+       n = strlcpy(params->name, value, RTE_COMPRESSDEV_NAME_MAX_LEN);
        if (n >= RTE_COMPRESSDEV_NAME_MAX_LEN)
                return -EINVAL;
 
index f03bdbd..0912004 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright(c) 2017 Intel Corporation
  */
 
+#include <rte_string_fns.h>
 #include <rte_malloc.h>
 
 #include "rte_cryptodev_pmd.h"
@@ -16,7 +17,7 @@ rte_cryptodev_pmd_parse_name_arg(const char *key __rte_unused,
        struct rte_cryptodev_pmd_init_params *params = extra_args;
        int n;
 
-       n = snprintf(params->name, RTE_CRYPTODEV_NAME_MAX_LEN, "%s", value);
+       n = strlcpy(params->name, value, RTE_CRYPTODEV_NAME_MAX_LEN);
        if (n >= RTE_CRYPTODEV_NAME_MAX_LEN)
                return -EINVAL;
 
index 8dcfeb9..0c91024 100644 (file)
@@ -16,6 +16,7 @@
 #include <sys/stat.h>
 #include <dirent.h>
 
+#include <rte_string_fns.h>
 #include <rte_eal.h>
 #include <rte_log.h>
 #include <rte_lcore.h>
@@ -139,7 +140,7 @@ eal_option_device_add(enum rte_devtype type, const char *optarg)
        }
 
        devopt->type = type;
-       ret = snprintf(devopt->arg, optlen, "%s", optarg);
+       ret = strlcpy(devopt->arg, optarg, optlen);
        if (ret < 0) {
                RTE_LOG(ERR, EAL, "Unable to copy device option\n");
                free(devopt);
index 1a97ece..14e493b 100644 (file)
@@ -9,6 +9,7 @@
 #include <stdarg.h>
 #include <sys/queue.h>
 
+#include <rte_string_fns.h>
 #include <rte_log.h>
 #include <rte_eal_memconfig.h>
 #include <rte_errno.h>
@@ -591,7 +592,7 @@ rte_efd_create(const char *name, uint32_t max_num_rules, uint32_t key_len,
                goto error_unlock_exit;
        }
        table->keys = key_array;
-       snprintf(table->name, sizeof(table->name), "%s", name);
+       strlcpy(table->name, name, sizeof(table->name));
 
        RTE_LOG(DEBUG, EFD, "Creating an EFD table with %u chunks,"
                        " which potentially supports %u entries\n",
index 4d4f079..3bd571a 100644 (file)
@@ -13,6 +13,7 @@
 #include <sys/types.h>
 #include <sys/queue.h>
 
+#include <rte_string_fns.h>
 #include <rte_byteorder.h>
 #include <rte_log.h>
 #include <rte_debug.h>
@@ -1362,8 +1363,7 @@ rte_event_pmd_allocate(const char *name, int socket_id)
 
                eventdev->data = eventdev_data;
 
-               snprintf(eventdev->data->name, RTE_EVENTDEV_NAME_MAX_LEN,
-                               "%s", name);
+               strlcpy(eventdev->data->name, name, RTE_EVENTDEV_NAME_MAX_LEN);
 
                eventdev->data->dev_id = dev_id;
                eventdev->data->socket_id = socket_id;
index fb652a2..24f7f7a 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright(c) 2017 Intel Corporation
  */
 
+#include <rte_string_fns.h>
 #include <rte_compat.h>
 #include <rte_flow_classify.h>
 #include "rte_flow_classify_parse.h"
@@ -285,8 +286,7 @@ rte_flow_classifier_create(struct rte_flow_classifier_params *params)
        }
 
        /* Save input parameters */
-       snprintf(cls->name, RTE_FLOW_CLASSIFIER_MAX_NAME_SZ, "%s",
-                       params->name);
+       strlcpy(cls->name, params->name, RTE_FLOW_CLASSIFIER_MAX_NAME_SZ);
 
        cls->socket_id = params->socket_id;
 
index b64bc53..9b8fde5 100644 (file)
@@ -6,6 +6,7 @@
 #include <stdlib.h>
 #include <errno.h>
 
+#include <rte_string_fns.h>
 #include <rte_errno.h>
 #include <rte_common.h>
 #include <rte_eal.h>
@@ -240,7 +241,7 @@ rte_jobstats_init(struct rte_jobstats *job, const char *name,
        job->target = target;
        job->update_period_cb = &default_update_function;
        rte_jobstats_reset(job);
-       snprintf(job->name, RTE_DIM(job->name), "%s", name == NULL ? "" : name);
+       strlcpy(job->name, name == NULL ? "" : name, RTE_DIM(job->name));
        job->context = NULL;
 
        return 0;
index 5715549..06c6283 100644 (file)
@@ -7,6 +7,7 @@
 #include <stdbool.h>
 #include <math.h>
 
+#include <rte_string_fns.h>
 #include <rte_mbuf.h>
 #include <rte_log.h>
 #include <rte_cycles.h>
@@ -309,8 +310,8 @@ rte_latencystats_get_names(struct rte_metric_name *names, uint16_t size)
                return NUM_LATENCY_STATS;
 
        for (i = 0; i < NUM_LATENCY_STATS; i++)
-               snprintf(names[i].name, sizeof(names[i].name),
-                               "%s", lat_stats_strings[i].name);
+               strlcpy(names[i].name, lat_stats_strings[i].name,
+                       sizeof(names[i].name));
 
        return NUM_LATENCY_STATS;
 }
index 702c01d..fd228f4 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <string.h>
 
+#include <rte_string_fns.h>
 #include <rte_eal.h>
 #include <rte_eal_memconfig.h>
 #include <rte_memory.h>
@@ -132,7 +133,7 @@ rte_member_create(const struct rte_member_parameters *params)
                RTE_MEMBER_LOG(ERR, "Create setsummary failed\n");
                goto error_unlock_exit;
        }
-       snprintf(setsum->name, sizeof(setsum->name), "%s", params->name);
+       strlcpy(setsum->name, params->name, sizeof(setsum->name));
        setsum->type = params->type;
        setsum->socket_id = params->socket_id;
        setsum->key_len = params->key_len;
index a27e1fa..e02eb70 100644 (file)
@@ -6,6 +6,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#include <rte_string_fns.h>
 #include <rte_mempool.h>
 #include <rte_errno.h>
 #include <rte_dev.h>
@@ -51,7 +52,7 @@ rte_mempool_register_ops(const struct rte_mempool_ops *h)
 
        ops_index = rte_mempool_ops_table.num_ops++;
        ops = &rte_mempool_ops_table.ops[ops_index];
-       snprintf(ops->name, sizeof(ops->name), "%s", h->name);
+       strlcpy(ops->name, h->name, sizeof(ops->name));
        ops->alloc = h->alloc;
        ops->free = h->free;
        ops->enqueue = h->enqueue;
index 49325d0..5672c59 100644 (file)
@@ -12,6 +12,7 @@
 #include <signal.h>
 #include <limits.h>
 
+#include <rte_string_fns.h>
 #include <rte_memcpy.h>
 #include <rte_atomic.h>
 
@@ -159,7 +160,7 @@ power_set_governor_userspace(struct rte_power_info *pi)
                goto out;
        }
        /* Save the original governor */
-       snprintf(pi->governor_ori, sizeof(pi->governor_ori), "%s", buf);
+       strlcpy(pi->governor_ori, buf, sizeof(pi->governor_ori));
 
        /* Write 'userspace' to the governor */
        val = fseek(f, 0, SEEK_SET);
index 61ff8db..336c138 100644 (file)
@@ -14,6 +14,7 @@
 #include <errno.h>
 #include <inttypes.h>
 
+#include <rte_string_fns.h>
 #include <rte_memcpy.h>
 #include <rte_atomic.h>
 
@@ -349,7 +350,7 @@ power_set_governor_performance(struct pstate_power_info *pi)
                goto out;
        }
        /* Save the original governor */
-       snprintf(pi->governor_ori, sizeof(pi->governor_ori), "%s", buf);
+       strlcpy(pi->governor_ori, buf, sizeof(pi->governor_ori));
 
        /* Write 'performance' to the governor */
        val = fseek(f, 0, SEEK_SET);
index 9f1e359..2b2f45d 100644 (file)
@@ -13,6 +13,7 @@
 #include <sys/types.h>
 #include <sys/queue.h>
 
+#include <rte_string_fns.h>
 #include <rte_byteorder.h>
 #include <rte_log.h>
 #include <rte_debug.h>
@@ -508,7 +509,7 @@ rte_rawdev_pmd_allocate(const char *name, size_t dev_priv_size, int socket_id)
        rawdev->dev_id = dev_id;
        rawdev->socket_id = socket_id;
        rawdev->started = 0;
-       snprintf(rawdev->name, RTE_RAWDEV_NAME_MAX_LEN, "%s", name);
+       strlcpy(rawdev->name, name, RTE_RAWDEV_NAME_MAX_LEN);
 
        rawdev->attached = RTE_RAWDEV_ATTACHED;
        rawdev_globals.nb_devs++;
index ecf539d..b15328b 100644 (file)
@@ -5,6 +5,7 @@
 #include <inttypes.h>
 #include <string.h>
 
+#include <rte_string_fns.h>
 #include <rte_log.h>
 #include <rte_mbuf.h>
 #include <rte_eal_memconfig.h>
@@ -82,7 +83,7 @@ rte_reorder_init(struct rte_reorder_buffer *b, unsigned int bufsize,
        }
 
        memset(b, 0, bufsize);
-       snprintf(b->name, sizeof(b->name), "%s", name);
+       strlcpy(b->name, name, sizeof(b->name));
        b->memsize = bufsize;
        b->order_buf.size = b->ready_buf.size = size;
        b->order_buf.mask = b->ready_buf.mask = size - 1;
@@ -161,7 +162,7 @@ rte_reorder_reset(struct rte_reorder_buffer *b)
        char name[RTE_REORDER_NAMESIZE];
 
        rte_reorder_free_mbufs(b);
-       snprintf(name, sizeof(name), "%s", b->name);
+       strlcpy(name, b->name, sizeof(name));
        /* No error checking as current values should be valid */
        rte_reorder_init(b, b->memsize, name, b->order_buf.size);
 }
index 1a4d9bd..60f63a6 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <string.h>
 
+#include <rte_string_fns.h>
 #include <rte_atomic.h>
 #include <rte_eal.h>
 #include <rte_eal_memconfig.h>
@@ -99,7 +100,7 @@ rte_stack_create(const char *name, unsigned int count, int socket_id,
        rte_stack_init(s, count, flags);
 
        /* Store the name for later lookups */
-       ret = snprintf(s->name, sizeof(s->name), "%s", name);
+       ret = strlcpy(s->name, name, sizeof(s->name));
        if (ret < 0 || ret >= (int)sizeof(s->name)) {
                rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);