From patchwork Wed Apr 3 14:45:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 52202 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A78F11B478; Wed, 3 Apr 2019 16:45:33 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id 14EFA1B464 for ; Wed, 3 Apr 2019 16:45:31 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Apr 2019 07:45:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,304,1549958400"; d="scan'208";a="312832755" Received: from silpixa00399126.ir.intel.com (HELO silpixa00399126.ger.corp.intel.com) ([10.237.222.236]) by orsmga005.jf.intel.com with ESMTP; 03 Apr 2019 07:45:30 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson Date: Wed, 3 Apr 2019 15:45:04 +0100 Message-Id: <20190403144505.46234-5-bruce.richardson@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190403144505.46234-1-bruce.richardson@intel.com> References: <20190403144505.46234-1-bruce.richardson@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 4/5] replace snprintf with strlcpy without adding extra include X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" For files that already have rte_string_fns.h included in them, we can do a straight replacement of snprintf(..."%s",...) with strlcpy. The changes in this patch were auto-generated via command: spatch --sp-file devtools/cocci/strlcpy-with-header.cocci --dir . --in-place Signed-off-by: Bruce Richardson --- app/pdump/main.c | 4 ++-- app/proc-info/main.c | 2 +- app/test-bbdev/main.c | 5 ++--- app/test/test_cmdline_etheraddr.c | 3 +-- app/test/test_cmdline_num.c | 3 +-- app/test/test_compressdev.c | 2 +- app/test/test_eal_flags.c | 2 +- drivers/bus/pci/bsd/pci.c | 2 +- drivers/bus/vdev/vdev.c | 2 +- drivers/net/bonding/rte_eth_bond_pmd.c | 14 +++++++------- drivers/net/dpaa2/dpaa2_ethdev.c | 7 +++---- drivers/net/failsafe/failsafe_args.c | 2 +- drivers/net/i40e/i40e_ethdev.c | 12 ++++++------ drivers/net/pcap/rte_eth_pcap.c | 8 ++++---- drivers/net/ring/rte_eth_ring.c | 3 ++- drivers/net/softnic/rte_eth_softnic_tap.c | 2 +- drivers/net/tap/rte_eth_tap.c | 9 ++++----- examples/cmdline/commands.c | 2 +- examples/cmdline/parse_obj_list.c | 2 +- examples/exception_path/main.c | 4 ++-- examples/ip_pipeline/kni.c | 2 +- examples/ip_pipeline/tap.c | 2 +- examples/l3fwd-power/main.c | 2 +- examples/multi_process/simple_mp/mp_commands.c | 2 +- examples/netmap_compat/bridge/bridge.c | 4 ++-- examples/netmap_compat/lib/compat_netmap.c | 2 +- examples/tep_termination/main.c | 2 +- examples/vhost/main.c | 2 +- examples/vhost_scsi/scsi.c | 9 ++++----- lib/librte_cmdline/cmdline.c | 2 +- lib/librte_cmdline/cmdline_parse.c | 5 +++-- lib/librte_cmdline/cmdline_parse_num.c | 2 +- lib/librte_cryptodev/rte_cryptodev.c | 4 ++-- lib/librte_distributor/rte_distributor.c | 2 +- lib/librte_distributor/rte_distributor_v20.c | 2 +- lib/librte_eal/common/eal_common_memzone.c | 2 +- lib/librte_eal/common/eal_common_tailqs.c | 2 +- lib/librte_ethdev/rte_ethdev.c | 6 +++--- lib/librte_hash/rte_cuckoo_hash.c | 2 +- lib/librte_hash/rte_fbk_hash.c | 2 +- lib/librte_kni/rte_kni.c | 6 +++--- lib/librte_lpm/rte_lpm.c | 4 ++-- lib/librte_lpm/rte_lpm6.c | 2 +- lib/librte_mempool/rte_mempool.c | 2 +- lib/librte_pdump/rte_pdump.c | 8 ++++---- lib/librte_pipeline/rte_pipeline.c | 2 +- lib/librte_ring/rte_ring.c | 2 +- 47 files changed, 85 insertions(+), 89 deletions(-) diff --git a/app/pdump/main.c b/app/pdump/main.c index ccf2a1d2f..ae0cf282f 100644 --- a/app/pdump/main.c +++ b/app/pdump/main.c @@ -189,12 +189,12 @@ parse_rxtxdev(const char *key, const char *value, void *extra_args) struct pdump_tuples *pt = extra_args; if (!strcmp(key, PDUMP_RX_DEV_ARG)) { - snprintf(pt->rx_dev, sizeof(pt->rx_dev), "%s", value); + strlcpy(pt->rx_dev, value, sizeof(pt->rx_dev)); /* identify the tx stream type for pcap vdev */ if (if_nametoindex(pt->rx_dev)) pt->rx_vdev_stream_type = IFACE; } else if (!strcmp(key, PDUMP_TX_DEV_ARG)) { - snprintf(pt->tx_dev, sizeof(pt->tx_dev), "%s", value); + strlcpy(pt->tx_dev, value, sizeof(pt->tx_dev)); /* identify the tx stream type for pcap vdev */ if (if_nametoindex(pt->tx_dev)) pt->tx_vdev_stream_type = IFACE; diff --git a/app/proc-info/main.c b/app/proc-info/main.c index b9acfa9ec..3cd53416d 100644 --- a/app/proc-info/main.c +++ b/app/proc-info/main.c @@ -193,7 +193,7 @@ proc_info_preparse_args(int argc, char **argv) proc_info_usage(prgname); return -1; } - snprintf(host_id, sizeof(host_id), "%s", argv[i+1]); + strlcpy(host_id, argv[i + 1], sizeof(host_id)); } } diff --git a/app/test-bbdev/main.c b/app/test-bbdev/main.c index 7af25224c..a2f8722ec 100644 --- a/app/test-bbdev/main.c +++ b/app/test-bbdev/main.c @@ -226,9 +226,8 @@ parse_args(int argc, char **argv, struct test_params *tp) TEST_ASSERT(strlen(optarg) > 0, "Config file name is null"); - snprintf(tp->test_vector_filename, - sizeof(tp->test_vector_filename), - "%s", optarg); + strlcpy(tp->test_vector_filename, optarg, + sizeof(tp->test_vector_filename)); break; case 'l': TEST_ASSERT(strlen(optarg) > 0, diff --git a/app/test/test_cmdline_etheraddr.c b/app/test/test_cmdline_etheraddr.c index 6ceba4b29..086108ab2 100644 --- a/app/test/test_cmdline_etheraddr.c +++ b/app/test/test_cmdline_etheraddr.c @@ -118,8 +118,7 @@ test_parse_etheraddr_invalid_param(void) /* try null result */ /* copy string to buffer */ - snprintf(buf, sizeof(buf), "%s", - ether_addr_valid_strs[0].str); + strlcpy(buf, ether_addr_valid_strs[0].str, sizeof(buf)); ret = cmdline_parse_etheraddr(NULL, buf, NULL, 0); if (ret == -1) { diff --git a/app/test/test_cmdline_num.c b/app/test/test_cmdline_num.c index ea6b9f1e3..4c97caf3d 100644 --- a/app/test/test_cmdline_num.c +++ b/app/test/test_cmdline_num.c @@ -318,8 +318,7 @@ test_parse_num_invalid_param(void) token.num_data.type = UINT32; /* copy string to buffer */ - snprintf(buf, sizeof(buf), "%s", - num_valid_positive_strs[0].str); + strlcpy(buf, num_valid_positive_strs[0].str, sizeof(buf)); /* try all null */ ret = cmdline_parse_num(NULL, NULL, NULL, 0); diff --git a/app/test/test_compressdev.c b/app/test/test_compressdev.c index 13cf26c9a..ae9fc8388 100644 --- a/app/test/test_compressdev.c +++ b/app/test/test_compressdev.c @@ -767,7 +767,7 @@ test_deflate_comp_decomp(const struct interim_data_params *int_data, for (i = 0; i < num_bufs; i++) { data_size = strlen(test_bufs[i]) + 1; buf_ptr = rte_pktmbuf_append(uncomp_bufs[i], data_size); - snprintf(buf_ptr, data_size, "%s", test_bufs[i]); + strlcpy(buf_ptr, test_bufs[i], data_size); } } diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index d626dd712..9112c96d0 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -58,7 +58,7 @@ get_hugepage_path(char * src, int src_len, char * dst, int dst_len) return 0; if (strncmp(tokens[2], "hugetlbfs", sizeof("hugetlbfs")) == 0) { - snprintf(dst, dst_len, "%s", tokens[1]); + strlcpy(dst, tokens[1], dst_len); return 1; } return 0; diff --git a/drivers/bus/pci/bsd/pci.c b/drivers/bus/pci/bsd/pci.c index d09f8ee5a..c7b90cb83 100644 --- a/drivers/bus/pci/bsd/pci.c +++ b/drivers/bus/pci/bsd/pci.c @@ -145,7 +145,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; diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c index 87f0e2b6b..04f76a63f 100644 --- a/drivers/bus/vdev/vdev.c +++ b/drivers/bus/vdev/vdev.c @@ -192,7 +192,7 @@ alloc_devargs(const char *name, const char *args) else devargs->args = strdup(""); - ret = snprintf(devargs->name, sizeof(devargs->name), "%s", name); + ret = strlcpy(devargs->name, name, sizeof(devargs->name)); if (ret < 0 || ret >= (int)sizeof(devargs->name)) { free(devargs->args); free(devargs); diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c index 154257ffe..f30422a6d 100644 --- a/drivers/net/bonding/rte_eth_bond_pmd.c +++ b/drivers/net/bonding/rte_eth_bond_pmd.c @@ -493,27 +493,27 @@ arp_op_name(uint16_t arp_op, char *buf, size_t buf_len) { switch (arp_op) { case ARP_OP_REQUEST: - snprintf(buf, buf_len, "%s", "ARP Request"); + strlcpy(buf, "ARP Request", buf_len); return; case ARP_OP_REPLY: - snprintf(buf, buf_len, "%s", "ARP Reply"); + strlcpy(buf, "ARP Reply", buf_len); return; case ARP_OP_REVREQUEST: - snprintf(buf, buf_len, "%s", "Reverse ARP Request"); + strlcpy(buf, "Reverse ARP Request", buf_len); return; case ARP_OP_REVREPLY: - snprintf(buf, buf_len, "%s", "Reverse ARP Reply"); + strlcpy(buf, "Reverse ARP Reply", buf_len); return; case ARP_OP_INVREQUEST: - snprintf(buf, buf_len, "%s", "Peer Identify Request"); + strlcpy(buf, "Peer Identify Request", buf_len); return; case ARP_OP_INVREPLY: - snprintf(buf, buf_len, "%s", "Peer Identify Reply"); + strlcpy(buf, "Peer Identify Reply", buf_len); return; default: break; } - snprintf(buf, buf_len, "%s", "Unknown"); + strlcpy(buf, "Unknown", buf_len); return; } #endif diff --git a/drivers/net/dpaa2/dpaa2_ethdev.c b/drivers/net/dpaa2/dpaa2_ethdev.c index 3fbc82977..c4f3a2ba9 100644 --- a/drivers/net/dpaa2/dpaa2_ethdev.c +++ b/drivers/net/dpaa2/dpaa2_ethdev.c @@ -1334,10 +1334,9 @@ dpaa2_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", - dpaa2_xstats_strings[i].name); + strlcpy(xstats_names[i].name, + dpaa2_xstats_strings[i].name, + sizeof(xstats_names[i].name)); return stat_cnt; } diff --git a/drivers/net/failsafe/failsafe_args.c b/drivers/net/failsafe/failsafe_args.c index c4b220c48..3351c5bca 100644 --- a/drivers/net/failsafe/failsafe_args.c +++ b/drivers/net/failsafe/failsafe_args.c @@ -102,7 +102,7 @@ fs_execute_cmd(struct sub_device *sdev, char *cmdline) ERROR("Command line allocation failed"); return -ENOMEM; } - snprintf(sdev->cmdline, len, "%s", cmdline); + strlcpy(sdev->cmdline, cmdline, len); /* Replace all commas in the command line by spaces */ for (i = 0; i < len; i++) if (sdev->cmdline[i] == ',') diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c index 891bdc061..b031bf4c6 100644 --- a/drivers/net/i40e/i40e_ethdev.c +++ b/drivers/net/i40e/i40e_ethdev.c @@ -3324,17 +3324,17 @@ static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev, /* Get stats from i40e_eth_stats struct */ for (i = 0; i < I40E_NB_ETH_XSTATS; i++) { - snprintf(xstats_names[count].name, - sizeof(xstats_names[count].name), - "%s", rte_i40e_stats_strings[i].name); + strlcpy(xstats_names[count].name, + rte_i40e_stats_strings[i].name, + sizeof(xstats_names[count].name)); count++; } /* Get individiual stats from i40e_hw_port struct */ for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) { - snprintf(xstats_names[count].name, - sizeof(xstats_names[count].name), - "%s", rte_i40e_hw_port_strings[i].name); + strlcpy(xstats_names[count].name, + rte_i40e_hw_port_strings[i].name, + sizeof(xstats_names[count].name)); count++; } diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c index 22aa49c9f..353538f16 100644 --- a/drivers/net/pcap/rte_eth_pcap.c +++ b/drivers/net/pcap/rte_eth_pcap.c @@ -1084,8 +1084,8 @@ eth_from_pcaps_common(struct rte_vdev_device *vdev, struct devargs_queue *queue = &rx_queues->queue[i]; pp->rx_pcap[i] = queue->pcap; - snprintf(rx->name, sizeof(rx->name), "%s", queue->name); - snprintf(rx->type, sizeof(rx->type), "%s", queue->type); + strlcpy(rx->name, queue->name, sizeof(rx->name)); + strlcpy(rx->type, queue->type, sizeof(rx->type)); } for (i = 0; i < nb_tx_queues; i++) { @@ -1094,8 +1094,8 @@ eth_from_pcaps_common(struct rte_vdev_device *vdev, pp->tx_dumper[i] = queue->dumper; pp->tx_pcap[i] = queue->pcap; - snprintf(tx->name, sizeof(tx->name), "%s", queue->name); - snprintf(tx->type, sizeof(tx->type), "%s", queue->type); + strlcpy(tx->name, queue->name, sizeof(tx->name)); + strlcpy(tx->type, queue->type, sizeof(tx->type)); } return 0; diff --git a/drivers/net/ring/rte_eth_ring.c b/drivers/net/ring/rte_eth_ring.c index aeb48f5ec..115a882b5 100644 --- a/drivers/net/ring/rte_eth_ring.c +++ b/drivers/net/ring/rte_eth_ring.c @@ -497,7 +497,8 @@ static int parse_kvlist (const char *key __rte_unused, const char *value, void * goto out; } - snprintf(info->list[info->count].name, sizeof(info->list[info->count].name), "%s", name); + strlcpy(info->list[info->count].name, name, + sizeof(info->list[info->count].name)); info->count++; diff --git a/drivers/net/softnic/rte_eth_softnic_tap.c b/drivers/net/softnic/rte_eth_softnic_tap.c index 0cac876ed..36fe9f028 100644 --- a/drivers/net/softnic/rte_eth_softnic_tap.c +++ b/drivers/net/softnic/rte_eth_softnic_tap.c @@ -91,7 +91,7 @@ softnic_tap_create(struct pmd_internals *p, memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* No packet information */ - snprintf(ifr.ifr_name, IFNAMSIZ, "%s", name); + strlcpy(ifr.ifr_name, name, IFNAMSIZ); status = ioctl(fd, TUNSETIFF, (void *)&ifr); if (status < 0) { diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 9aae4c77f..e9fda8cf6 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -760,9 +760,9 @@ tap_ioctl(struct pmd_internals *pmd, unsigned long request, */ apply: if (remote) - snprintf(ifr->ifr_name, IFNAMSIZ, "%s", pmd->remote_iface); + strlcpy(ifr->ifr_name, pmd->remote_iface, IFNAMSIZ); else if (mode == LOCAL_ONLY || mode == LOCAL_AND_REMOTE) - snprintf(ifr->ifr_name, IFNAMSIZ, "%s", pmd->name); + strlcpy(ifr->ifr_name, pmd->name, IFNAMSIZ); switch (request) { case SIOCSIFFLAGS: /* fetch current flags to leave other flags untouched */ @@ -1714,7 +1714,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, pmd = dev->data->dev_private; dev->process_private = process_private; pmd->dev = dev; - snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name); + strlcpy(pmd->name, tap_name, sizeof(pmd->name)); pmd->type = type; pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0); @@ -1823,8 +1823,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, pmd->name, remote_iface); goto error_remote; } - snprintf(pmd->remote_iface, RTE_ETH_NAME_MAX_LEN, - "%s", remote_iface); + strlcpy(pmd->remote_iface, remote_iface, RTE_ETH_NAME_MAX_LEN); /* Save state of remote device */ tap_ioctl(pmd, SIOCGIFFLAGS, &pmd->remote_initial_flags, 0, REMOTE_ONLY); diff --git a/examples/cmdline/commands.c b/examples/cmdline/commands.c index 06916d783..e96739f34 100644 --- a/examples/cmdline/commands.c +++ b/examples/cmdline/commands.c @@ -145,7 +145,7 @@ static void cmd_obj_add_parsed(void *parsed_result, cmdline_printf(cl, "mem error\n"); return; } - snprintf(o->name, sizeof(o->name), "%s", res->name); + strlcpy(o->name, res->name, sizeof(o->name)); o->ip = res->ip; SLIST_INSERT_HEAD(&global_obj_list, o, next); diff --git a/examples/cmdline/parse_obj_list.c b/examples/cmdline/parse_obj_list.c index 69eb448e7..5d29f9d59 100644 --- a/examples/cmdline/parse_obj_list.c +++ b/examples/cmdline/parse_obj_list.c @@ -98,7 +98,7 @@ int complete_get_elt_obj_list(cmdline_parse_token_hdr_t *tk, return -1; if (dstbuf) - snprintf(dstbuf, size, "%s", o->name); + strlcpy(dstbuf, o->name, size); return 0; } diff --git a/examples/exception_path/main.c b/examples/exception_path/main.c index 8f37f5fbf..0d79e5a24 100644 --- a/examples/exception_path/main.c +++ b/examples/exception_path/main.c @@ -176,7 +176,7 @@ static int tap_create(char *name) ifr.ifr_flags = IFF_TAP | IFF_NO_PI; if (name && *name) - snprintf(ifr.ifr_name, IFNAMSIZ, "%s", name); + strlcpy(ifr.ifr_name, name, IFNAMSIZ); ret = ioctl(fd, TUNSETIFF, (void *) &ifr); if (ret < 0) { @@ -185,7 +185,7 @@ static int tap_create(char *name) } if (name) - snprintf(name, IFNAMSIZ, "%s", ifr.ifr_name); + strlcpy(name, ifr.ifr_name, IFNAMSIZ); return fd; } diff --git a/examples/ip_pipeline/kni.c b/examples/ip_pipeline/kni.c index 7e5ff0543..e3d0b3758 100644 --- a/examples/ip_pipeline/kni.c +++ b/examples/ip_pipeline/kni.c @@ -126,7 +126,7 @@ kni_create(const char *name, struct kni_params *params) rte_eth_dev_info_get(link->port_id, &dev_info); memset(&kni_conf, 0, sizeof(kni_conf)); - snprintf(kni_conf.name, RTE_KNI_NAMESIZE, "%s", name); + strlcpy(kni_conf.name, name, RTE_KNI_NAMESIZE); kni_conf.force_bind = params->force_bind; kni_conf.core_id = params->thread_id; kni_conf.group_id = link->port_id; diff --git a/examples/ip_pipeline/tap.c b/examples/ip_pipeline/tap.c index ea979bdf8..adae640c1 100644 --- a/examples/ip_pipeline/tap.c +++ b/examples/ip_pipeline/tap.c @@ -75,7 +75,7 @@ tap_create(const char *name) memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* No packet information */ - snprintf(ifr.ifr_name, IFNAMSIZ, "%s", name); + strlcpy(ifr.ifr_name, name, IFNAMSIZ); status = ioctl(fd, TUNSETIFF, (void *) &ifr); if (status < 0) { diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c index 9c7b31564..3b448acc4 100644 --- a/examples/l3fwd-power/main.c +++ b/examples/l3fwd-power/main.c @@ -1384,7 +1384,7 @@ parse_ep_config(const char *q_arg) ep_med_edpi = EMPTY_POLL_MED_THRESHOLD; ep_hgh_edpi = EMPTY_POLL_MED_THRESHOLD; - snprintf(s, sizeof(s), "%s", p); + strlcpy(s, p, sizeof(s)); num_arg = rte_strsplit(s, sizeof(s), str_fld, 3, ','); diff --git a/examples/multi_process/simple_mp/mp_commands.c b/examples/multi_process/simple_mp/mp_commands.c index e4df6ff01..bdf494772 100644 --- a/examples/multi_process/simple_mp/mp_commands.c +++ b/examples/multi_process/simple_mp/mp_commands.c @@ -48,7 +48,7 @@ static void cmd_send_parsed(void *parsed_result, if (rte_mempool_get(message_pool, &msg) < 0) rte_panic("Failed to get message buffer\n"); - snprintf((char *)msg, STR_TOKEN_SIZE, "%s", res->message); + strlcpy((char *)msg, res->message, STR_TOKEN_SIZE); if (rte_ring_enqueue(send_ring, msg) < 0) { printf("Failed to send message - message discarded\n"); rte_mempool_put(message_pool, msg); diff --git a/examples/netmap_compat/bridge/bridge.c b/examples/netmap_compat/bridge/bridge.c index 216e0105a..d40e163b0 100644 --- a/examples/netmap_compat/bridge/bridge.c +++ b/examples/netmap_compat/bridge/bridge.c @@ -174,7 +174,7 @@ netmap_port_open(uint32_t idx) port->fd = rte_netmap_open("/dev/netmap", O_RDWR); - snprintf(req.nr_name, sizeof(req.nr_name), "%s", port->str); + strlcpy(req.nr_name, port->str, sizeof(req.nr_name)); req.nr_version = NETMAP_API; req.nr_ringid = 0; @@ -184,7 +184,7 @@ netmap_port_open(uint32_t idx) return err; } - snprintf(req.nr_name, sizeof(req.nr_name), "%s", port->str); + strlcpy(req.nr_name, port->str, sizeof(req.nr_name)); req.nr_version = NETMAP_API; req.nr_ringid = 0; diff --git a/examples/netmap_compat/lib/compat_netmap.c b/examples/netmap_compat/lib/compat_netmap.c index 0be0663ed..10a437943 100644 --- a/examples/netmap_compat/lib/compat_netmap.c +++ b/examples/netmap_compat/lib/compat_netmap.c @@ -302,7 +302,7 @@ netmap_regif(struct nmreq *req, uint32_t idx, uint16_t port) if (req->nr_ringid != 0) return -EINVAL; - snprintf(nmif->ni_name, sizeof(nmif->ni_name), "%s", req->nr_name); + strlcpy(nmif->ni_name, req->nr_name, sizeof(nmif->ni_name)); nmif->ni_version = req->nr_version; /* Netmap uses ni_(r|t)x_rings + 1 */ diff --git a/examples/tep_termination/main.c b/examples/tep_termination/main.c index d6379e31e..e0fe7bd2f 100644 --- a/examples/tep_termination/main.c +++ b/examples/tep_termination/main.c @@ -191,7 +191,7 @@ us_vhost_parse_basename(const char *q_arg) if (strlen(q_arg) >= MAX_BASENAME_SZ) return -1; else - snprintf((char *)&dev_basename, MAX_BASENAME_SZ, "%s", q_arg); + strlcpy((char *)&dev_basename, q_arg, MAX_BASENAME_SZ); return 0; } diff --git a/examples/vhost/main.c b/examples/vhost/main.c index 5e914f58e..8f7b758c3 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -366,7 +366,7 @@ us_vhost_parse_socket_path(const char *q_arg) return -1; } - snprintf(socket_files + nb_sockets * PATH_MAX, PATH_MAX, "%s", q_arg); + strlcpy(socket_files + nb_sockets * PATH_MAX, q_arg, PATH_MAX); nb_sockets++; return 0; diff --git a/examples/vhost_scsi/scsi.c b/examples/vhost_scsi/scsi.c index 0c2fa3e6a..b1529afdc 100644 --- a/examples/vhost_scsi/scsi.c +++ b/examples/vhost_scsi/scsi.c @@ -234,8 +234,8 @@ vhost_bdev_scsi_inquiry_command(struct vhost_block_dev *bdev, desig->reserved0 = 0; desig->piv = 1; desig->reserved1 = 0; - desig->len = snprintf((char *)desig->desig, - 255, "%s", bdev->name); + desig->len = strlcpy((char *)desig->desig, bdev->name, + 255); len += sizeof(struct scsi_desig_desc) + desig->len; buf += sizeof(struct scsi_desig_desc) + desig->len; @@ -281,9 +281,8 @@ vhost_bdev_scsi_inquiry_command(struct vhost_block_dev *bdev, sizeof(inqdata->t10_vendor_id)); /* PRODUCT IDENTIFICATION */ - snprintf((char *)inqdata->product_id, - RTE_DIM(inqdata->product_id), "%s", - bdev->product_name); + strlcpy((char *)inqdata->product_id, bdev->product_name, + RTE_DIM(inqdata->product_id)); /* PRODUCT REVISION LEVEL */ strlcpy((char *)inqdata->product_rev, "0001", diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c index d9042f048..53cda84c1 100644 --- a/lib/librte_cmdline/cmdline.c +++ b/lib/librte_cmdline/cmdline.c @@ -69,7 +69,7 @@ cmdline_set_prompt(struct cmdline *cl, const char *prompt) { if (!cl || !prompt) return; - snprintf(cl->prompt, sizeof(cl->prompt), "%s", prompt); + strlcpy(cl->prompt, prompt, sizeof(cl->prompt)); } struct cmdline * diff --git a/lib/librte_cmdline/cmdline_parse.c b/lib/librte_cmdline/cmdline_parse.c index 9666e90c2..b57b30e8f 100644 --- a/lib/librte_cmdline/cmdline_parse.c +++ b/lib/librte_cmdline/cmdline_parse.c @@ -394,8 +394,9 @@ cmdline_complete(struct cmdline *cl, const char *buf, int *state, if (!strncmp(partial_tok, tmpbuf, partial_tok_len)) { if (comp_len == -1) { - snprintf(comp_buf, sizeof(comp_buf), - "%s", tmpbuf + partial_tok_len); + strlcpy(comp_buf, + tmpbuf + partial_tok_len, + sizeof(comp_buf)); comp_len = strnlen(tmpbuf + partial_tok_len, sizeof(tmpbuf) - partial_tok_len); diff --git a/lib/librte_cmdline/cmdline_parse_num.c b/lib/librte_cmdline/cmdline_parse_num.c index 55c7a8148..182ac12f0 100644 --- a/lib/librte_cmdline/cmdline_parse_num.c +++ b/lib/librte_cmdline/cmdline_parse_num.c @@ -340,7 +340,7 @@ cmdline_get_help_num(cmdline_parse_token_hdr_t *tk, char *dstbuf, unsigned int s /* if (nd.type >= (sizeof(num_help)/sizeof(const char *))) */ /* return -1; */ - ret = snprintf(dstbuf, size, "%s", num_help[nd.type]); + ret = strlcpy(dstbuf, num_help[nd.type], size); if (ret < 0) return -1; dstbuf[size-1] = '\0'; diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c index 871d7dda8..a48863d81 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -694,8 +694,8 @@ rte_cryptodev_pmd_allocate(const char *name, int socket_id) cryptodev->data = cryptodev_data; - snprintf(cryptodev->data->name, RTE_CRYPTODEV_NAME_MAX_LEN, - "%s", name); + strlcpy(cryptodev->data->name, name, + RTE_CRYPTODEV_NAME_MAX_LEN); cryptodev->data->dev_id = dev_id; cryptodev->data->socket_id = socket_id; diff --git a/lib/librte_distributor/rte_distributor.c b/lib/librte_distributor/rte_distributor.c index d50598377..208abfb1d 100644 --- a/lib/librte_distributor/rte_distributor.c +++ b/lib/librte_distributor/rte_distributor.c @@ -625,7 +625,7 @@ rte_distributor_create_v1705(const char *name, } d = mz->addr; - snprintf(d->name, sizeof(d->name), "%s", name); + strlcpy(d->name, name, sizeof(d->name)); d->num_workers = num_workers; d->alg_type = alg_type; diff --git a/lib/librte_distributor/rte_distributor_v20.c b/lib/librte_distributor/rte_distributor_v20.c index 9566b53f2..cd5940713 100644 --- a/lib/librte_distributor/rte_distributor_v20.c +++ b/lib/librte_distributor/rte_distributor_v20.c @@ -386,7 +386,7 @@ rte_distributor_create_v20(const char *name, } d = mz->addr; - snprintf(d->name, sizeof(d->name), "%s", name); + strlcpy(d->name, name, sizeof(d->name)); d->num_workers = num_workers; distributor_list = RTE_TAILQ_CAST(rte_distributor_tailq.head, diff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c index 664df5b9f..521ad7ca1 100644 --- a/lib/librte_eal/common/eal_common_memzone.c +++ b/lib/librte_eal/common/eal_common_memzone.c @@ -171,7 +171,7 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, return NULL; } - snprintf(mz->name, sizeof(mz->name), "%s", name); + strlcpy(mz->name, name, sizeof(mz->name)); mz->iova = rte_malloc_virt2iova(mz_addr); mz->addr = mz_addr; mz->len = requested_len == 0 ? diff --git a/lib/librte_eal/common/eal_common_tailqs.c b/lib/librte_eal/common/eal_common_tailqs.c index babd3b30a..ca2a7d32a 100644 --- a/lib/librte_eal/common/eal_common_tailqs.c +++ b/lib/librte_eal/common/eal_common_tailqs.c @@ -80,7 +80,7 @@ rte_eal_tailq_create(const char *name) mcfg = rte_eal_get_configuration()->mem_config; head = &mcfg->tailq_head[rte_tailqs_count]; - snprintf(head->name, sizeof(head->name) - 1, "%s", name); + strlcpy(head->name, name, sizeof(head->name) - 1); TAILQ_INIT(&head->tailq_head); rte_tailqs_count++; } diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 10bdfb37e..8b25c2adb 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -2068,9 +2068,9 @@ rte_eth_basic_stats_get_names(struct rte_eth_dev *dev, uint16_t num_q; for (idx = 0; idx < RTE_NB_STATS; idx++) { - snprintf(xstats_names[cnt_used_entries].name, - sizeof(xstats_names[0].name), - "%s", rte_stats_strings[idx].name); + strlcpy(xstats_names[cnt_used_entries].name, + rte_stats_strings[idx].name, + sizeof(xstats_names[0].name)); cnt_used_entries++; } num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c index 0dddce226..7103b871f 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -379,7 +379,7 @@ rte_hash_create(const struct rte_hash_parameters *params) default_hash_func = (rte_hash_function)rte_hash_crc; #endif /* Setup hash context */ - snprintf(h->name, sizeof(h->name), "%s", params->name); + strlcpy(h->name, params->name, sizeof(h->name)); h->entries = params->entries; h->key_len = params->key_len; h->key_entry_size = key_entry_size; diff --git a/lib/librte_hash/rte_fbk_hash.c b/lib/librte_hash/rte_fbk_hash.c index c9b470d7e..9360f7981 100644 --- a/lib/librte_hash/rte_fbk_hash.c +++ b/lib/librte_hash/rte_fbk_hash.c @@ -141,7 +141,7 @@ rte_fbk_hash_create(const struct rte_fbk_hash_params *params) #endif /* Set up hash table context. */ - snprintf(ht->name, sizeof(ht->name), "%s", params->name); + strlcpy(ht->name, params->name, sizeof(ht->name)); ht->entries = params->entries; ht->entries_per_bucket = params->entries_per_bucket; ht->used_entries = 0; diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c index 192f2fed0..946459c79 100644 --- a/lib/librte_kni/rte_kni.c +++ b/lib/librte_kni/rte_kni.c @@ -234,7 +234,7 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool, goto kni_fail; } - snprintf(kni->name, RTE_KNI_NAMESIZE, "%s", conf->name); + strlcpy(kni->name, conf->name, RTE_KNI_NAMESIZE); if (ops) memcpy(&kni->ops, ops, sizeof(struct rte_kni_ops)); @@ -255,7 +255,7 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool, memcpy(dev_info.mac_addr, conf->mac_addr, ETHER_ADDR_LEN); - snprintf(dev_info.name, RTE_KNI_NAMESIZE, "%s", conf->name); + strlcpy(dev_info.name, conf->name, RTE_KNI_NAMESIZE); RTE_LOG(INFO, KNI, "pci: %02x:%02x:%02x \t %02x:%02x\n", dev_info.bus, dev_info.devid, dev_info.function, @@ -400,7 +400,7 @@ rte_kni_release(struct rte_kni *kni) if (te == NULL) goto unlock; - snprintf(dev_info.name, sizeof(dev_info.name), "%s", kni->name); + strlcpy(dev_info.name, kni->name, sizeof(dev_info.name)); if (ioctl(kni_fd, RTE_KNI_IOCTL_RELEASE, &dev_info) < 0) { RTE_LOG(ERR, KNI, "Fail to release kni device\n"); goto unlock; diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c index d00b13d93..6b7b28a2e 100644 --- a/lib/librte_lpm/rte_lpm.c +++ b/lib/librte_lpm/rte_lpm.c @@ -205,7 +205,7 @@ rte_lpm_create_v20(const char *name, int socket_id, int max_rules, /* Save user arguments. */ lpm->max_rules = max_rules; - snprintf(lpm->name, sizeof(lpm->name), "%s", name); + strlcpy(lpm->name, name, sizeof(lpm->name)); te->data = lpm; @@ -308,7 +308,7 @@ rte_lpm_create_v1604(const char *name, int socket_id, /* Save user arguments. */ lpm->max_rules = config->max_rules; lpm->number_tbl8s = config->number_tbl8s; - snprintf(lpm->name, sizeof(lpm->name), "%s", name); + strlcpy(lpm->name, name, sizeof(lpm->name)); te->data = lpm; diff --git a/lib/librte_lpm/rte_lpm6.c b/lib/librte_lpm/rte_lpm6.c index 6212003f4..a91803113 100644 --- a/lib/librte_lpm/rte_lpm6.c +++ b/lib/librte_lpm/rte_lpm6.c @@ -352,7 +352,7 @@ rte_lpm6_create(const char *name, int socket_id, /* Save user arguments. */ lpm->max_rules = config->max_rules; lpm->number_tbl8s = config->number_tbl8s; - snprintf(lpm->name, sizeof(lpm->name), "%s", name); + strlcpy(lpm->name, name, sizeof(lpm->name)); lpm->rules_tbl = rules_tbl; lpm->tbl8_pool = tbl8_pool; lpm->tbl8_hdrs = tbl8_hdrs; diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index 683b216f9..69bd2a65c 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -864,7 +864,7 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, /* init the mempool structure */ mp = mz->addr; memset(mp, 0, MEMPOOL_HEADER_SIZE(mp, cache_size)); - ret = snprintf(mp->name, sizeof(mp->name), "%s", name); + ret = strlcpy(mp->name, name, sizeof(mp->name)); if (ret < 0 || ret >= (int)sizeof(mp->name)) { rte_errno = ENAMETOOLONG; goto exit_unlock; diff --git a/lib/librte_pdump/rte_pdump.c b/lib/librte_pdump/rte_pdump.c index 4f38ac58b..14744b9ff 100644 --- a/lib/librte_pdump/rte_pdump.c +++ b/lib/librte_pdump/rte_pdump.c @@ -501,15 +501,15 @@ pdump_prepare_client_request(char *device, uint16_t queue, req->flags = flags; req->op = operation; if ((operation & ENABLE) != 0) { - snprintf(req->data.en_v1.device, - sizeof(req->data.en_v1.device), "%s", device); + strlcpy(req->data.en_v1.device, device, + sizeof(req->data.en_v1.device)); req->data.en_v1.queue = queue; req->data.en_v1.ring = ring; req->data.en_v1.mp = mp; req->data.en_v1.filter = filter; } else { - snprintf(req->data.dis_v1.device, - sizeof(req->data.dis_v1.device), "%s", device); + strlcpy(req->data.dis_v1.device, device, + sizeof(req->data.dis_v1.device)); req->data.dis_v1.queue = queue; req->data.dis_v1.ring = NULL; req->data.dis_v1.mp = NULL; diff --git a/lib/librte_pipeline/rte_pipeline.c b/lib/librte_pipeline/rte_pipeline.c index 2c047a8a4..f5f397d29 100644 --- a/lib/librte_pipeline/rte_pipeline.c +++ b/lib/librte_pipeline/rte_pipeline.c @@ -214,7 +214,7 @@ rte_pipeline_create(struct rte_pipeline_params *params) } /* Save input parameters */ - snprintf(p->name, RTE_PIPELINE_MAX_NAME_SZ, "%s", params->name); + strlcpy(p->name, params->name, RTE_PIPELINE_MAX_NAME_SZ); p->socket_id = params->socket_id; p->offset_port_id = params->offset_port_id; diff --git a/lib/librte_ring/rte_ring.c b/lib/librte_ring/rte_ring.c index d215acecc..a542f6f5d 100644 --- a/lib/librte_ring/rte_ring.c +++ b/lib/librte_ring/rte_ring.c @@ -78,7 +78,7 @@ rte_ring_init(struct rte_ring *r, const char *name, unsigned count, /* init the ring structure */ memset(r, 0, sizeof(*r)); - ret = snprintf(r->name, sizeof(r->name), "%s", name); + ret = strlcpy(r->name, name, sizeof(r->name)); if (ret < 0 || ret >= (int)sizeof(r->name)) return -ENAMETOOLONG; r->flags = flags;