* [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying
@ 2019-04-03 14:45 Bruce Richardson
2019-04-03 14:45 ` Bruce Richardson
` (7 more replies)
0 siblings, 8 replies; 32+ messages in thread
From: Bruce Richardson @ 2019-04-03 14:45 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
There are quite a few instances remaining in DPDK where snprintf is being
used for string copying. These were not being picked up by our existing
coccinelle script, but that can be fixed by editing the script and running
it against our code. In the process a bug was found and fixed in the
bonding pmd, where we were incorrectly specifiying the buffer length
parameter to snprintf.
The actual replacement was done in two phases - first replacing all
instances where only the snprintf line in question needed changing, then
fixing the other instances where we also needed to add in the header
include. [Using two stages allowed the header addition to be automated too,
since we had a list of files where every one needed the header inclusion]
Bruce Richardson (5):
net/bonding: fix buffer length when printing strings
devtools/cocci: make strlcpy replacement smarter
devtools/cocci: create safer version of strlcpy script
replace snprintf with strlcpy without adding extra include
replace snprintf with strlcpy
app/pdump/main.c | 4 +--
app/proc-info/main.c | 2 +-
app/test-acl/main.c | 3 +-
app/test-bbdev/main.c | 5 ++-
app/test-eventdev/evt_options.c | 3 +-
app/test-pmd/cmdline_flow.c | 13 +++----
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 +-
app/test/test_table_acl.c | 11 +++---
devtools/cocci/strlcpy-with-header.cocci | 12 +++++++
devtools/cocci/strlcpy.cocci | 3 +-
drivers/bus/dpaa/base/fman/of.c | 7 ++--
drivers/bus/pci/bsd/pci.c | 2 +-
drivers/bus/pci/linux/pci_uio.c | 3 +-
drivers/bus/vdev/vdev.c | 2 +-
.../crypto/aesni_mb/rte_aesni_mb_pmd_ops.c | 3 +-
.../aesni_mb/rte_aesni_mb_pmd_ops_compat.c | 3 +-
drivers/crypto/ccp/rte_ccp_pmd.c | 6 ++--
.../scheduler/rte_cryptodev_scheduler.c | 8 ++---
drivers/event/opdl/opdl_ring.c | 3 +-
drivers/net/af_packet/rte_eth_af_packet.c | 5 +--
drivers/net/ark/ark_pktchkr.c | 3 +-
drivers/net/ark/ark_pktgen.c | 3 +-
drivers/net/atlantic/atl_ethdev.c | 5 +--
drivers/net/bnx2x/bnx2x_ethdev.c | 8 ++---
drivers/net/bnxt/bnxt_stats.c | 36 +++++++++----------
drivers/net/bonding/rte_eth_bond_pmd.c | 23 ++++++------
drivers/net/dpaa/dpaa_ethdev.c | 8 ++---
drivers/net/dpaa2/dpaa2_ethdev.c | 7 ++--
drivers/net/e1000/igb_ethdev.c | 17 ++++-----
drivers/net/ena/ena_ethdev.c | 11 +++---
drivers/net/failsafe/failsafe_args.c | 2 +-
drivers/net/failsafe/failsafe_eal.c | 6 ++--
drivers/net/i40e/i40e_ethdev.c | 12 +++----
drivers/net/i40e/rte_pmd_i40e.c | 5 +--
drivers/net/ice/ice_ethdev.c | 11 +++---
drivers/net/ixgbe/ixgbe_ethdev.c | 35 +++++++++---------
drivers/net/kni/rte_eth_kni.c | 3 +-
drivers/net/liquidio/lio_ethdev.c | 5 +--
drivers/net/mvneta/mvneta_ethdev.c | 3 +-
drivers/net/mvpp2/mrvl_ethdev.c | 5 +--
drivers/net/pcap/rte_eth_pcap.c | 8 ++---
drivers/net/qede/qede_ethdev.c | 22 ++++++------
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 +++--
drivers/net/virtio/virtio_user/vhost_user.c | 3 +-
.../net/virtio/virtio_user/virtio_user_dev.c | 3 +-
examples/cmdline/commands.c | 2 +-
examples/cmdline/parse_obj_list.c | 2 +-
examples/ethtool/lib/rte_ethtool.c | 8 ++---
examples/exception_path/main.c | 4 +--
examples/ip_pipeline/kni.c | 2 +-
examples/ip_pipeline/tap.c | 2 +-
examples/l2fwd-crypto/main.c | 4 +--
examples/l3fwd-power/main.c | 2 +-
.../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 +++--
examples/vm_power_manager/channel_manager.c | 7 ++--
examples/vm_power_manager/channel_monitor.c | 14 ++++----
lib/librte_acl/rte_acl.c | 3 +-
lib/librte_bbdev/rte_bbdev.c | 3 +-
lib/librte_cfgfile/rte_cfgfile.c | 22 ++++++------
lib/librte_cmdline/cmdline.c | 2 +-
lib/librte_cmdline/cmdline_parse.c | 5 +--
lib/librte_cmdline/cmdline_parse_num.c | 2 +-
lib/librte_compressdev/rte_compressdev.c | 5 +--
lib/librte_compressdev/rte_compressdev_pmd.c | 3 +-
lib/librte_cryptodev/rte_cryptodev.c | 4 +--
lib/librte_cryptodev/rte_cryptodev_pmd.c | 3 +-
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_options.c | 3 +-
lib/librte_eal/common/eal_common_tailqs.c | 2 +-
lib/librte_efd/rte_efd.c | 3 +-
lib/librte_ethdev/rte_ethdev.c | 6 ++--
lib/librte_eventdev/rte_eventdev.c | 4 +--
lib/librte_flow_classify/rte_flow_classify.c | 4 +--
lib/librte_hash/rte_cuckoo_hash.c | 2 +-
lib/librte_hash/rte_fbk_hash.c | 2 +-
lib/librte_jobstats/rte_jobstats.c | 3 +-
lib/librte_kni/rte_kni.c | 6 ++--
lib/librte_latencystats/rte_latencystats.c | 5 +--
lib/librte_lpm/rte_lpm.c | 4 +--
lib/librte_lpm/rte_lpm6.c | 2 +-
lib/librte_member/rte_member.c | 3 +-
lib/librte_mempool/rte_mempool.c | 2 +-
lib/librte_mempool/rte_mempool_ops.c | 3 +-
lib/librte_pdump/rte_pdump.c | 8 ++---
lib/librte_pipeline/rte_pipeline.c | 2 +-
lib/librte_power/power_acpi_cpufreq.c | 3 +-
lib/librte_power/power_pstate_cpufreq.c | 3 +-
lib/librte_rawdev/rte_rawdev.c | 3 +-
lib/librte_reorder/rte_reorder.c | 5 +--
lib/librte_ring/rte_ring.c | 2 +-
102 files changed, 302 insertions(+), 270 deletions(-)
create mode 100644 devtools/cocci/strlcpy-with-header.cocci
--
2.20.1
^ permalink raw reply [flat|nested] 32+ messages in thread
* [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying
2019-04-03 14:45 [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying Bruce Richardson
@ 2019-04-03 14:45 ` Bruce Richardson
2019-04-03 14:45 ` [dpdk-dev] [PATCH 1/5] net/bonding: fix buffer length when printing strings Bruce Richardson
` (6 subsequent siblings)
7 siblings, 0 replies; 32+ messages in thread
From: Bruce Richardson @ 2019-04-03 14:45 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
There are quite a few instances remaining in DPDK where snprintf is being
used for string copying. These were not being picked up by our existing
coccinelle script, but that can be fixed by editing the script and running
it against our code. In the process a bug was found and fixed in the
bonding pmd, where we were incorrectly specifiying the buffer length
parameter to snprintf.
The actual replacement was done in two phases - first replacing all
instances where only the snprintf line in question needed changing, then
fixing the other instances where we also needed to add in the header
include. [Using two stages allowed the header addition to be automated too,
since we had a list of files where every one needed the header inclusion]
Bruce Richardson (5):
net/bonding: fix buffer length when printing strings
devtools/cocci: make strlcpy replacement smarter
devtools/cocci: create safer version of strlcpy script
replace snprintf with strlcpy without adding extra include
replace snprintf with strlcpy
app/pdump/main.c | 4 +--
app/proc-info/main.c | 2 +-
app/test-acl/main.c | 3 +-
app/test-bbdev/main.c | 5 ++-
app/test-eventdev/evt_options.c | 3 +-
app/test-pmd/cmdline_flow.c | 13 +++----
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 +-
app/test/test_table_acl.c | 11 +++---
devtools/cocci/strlcpy-with-header.cocci | 12 +++++++
devtools/cocci/strlcpy.cocci | 3 +-
drivers/bus/dpaa/base/fman/of.c | 7 ++--
drivers/bus/pci/bsd/pci.c | 2 +-
drivers/bus/pci/linux/pci_uio.c | 3 +-
drivers/bus/vdev/vdev.c | 2 +-
.../crypto/aesni_mb/rte_aesni_mb_pmd_ops.c | 3 +-
.../aesni_mb/rte_aesni_mb_pmd_ops_compat.c | 3 +-
drivers/crypto/ccp/rte_ccp_pmd.c | 6 ++--
.../scheduler/rte_cryptodev_scheduler.c | 8 ++---
drivers/event/opdl/opdl_ring.c | 3 +-
drivers/net/af_packet/rte_eth_af_packet.c | 5 +--
drivers/net/ark/ark_pktchkr.c | 3 +-
drivers/net/ark/ark_pktgen.c | 3 +-
drivers/net/atlantic/atl_ethdev.c | 5 +--
drivers/net/bnx2x/bnx2x_ethdev.c | 8 ++---
drivers/net/bnxt/bnxt_stats.c | 36 +++++++++----------
drivers/net/bonding/rte_eth_bond_pmd.c | 23 ++++++------
drivers/net/dpaa/dpaa_ethdev.c | 8 ++---
drivers/net/dpaa2/dpaa2_ethdev.c | 7 ++--
drivers/net/e1000/igb_ethdev.c | 17 ++++-----
drivers/net/ena/ena_ethdev.c | 11 +++---
drivers/net/failsafe/failsafe_args.c | 2 +-
drivers/net/failsafe/failsafe_eal.c | 6 ++--
drivers/net/i40e/i40e_ethdev.c | 12 +++----
drivers/net/i40e/rte_pmd_i40e.c | 5 +--
drivers/net/ice/ice_ethdev.c | 11 +++---
drivers/net/ixgbe/ixgbe_ethdev.c | 35 +++++++++---------
drivers/net/kni/rte_eth_kni.c | 3 +-
drivers/net/liquidio/lio_ethdev.c | 5 +--
drivers/net/mvneta/mvneta_ethdev.c | 3 +-
drivers/net/mvpp2/mrvl_ethdev.c | 5 +--
drivers/net/pcap/rte_eth_pcap.c | 8 ++---
drivers/net/qede/qede_ethdev.c | 22 ++++++------
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 +++--
drivers/net/virtio/virtio_user/vhost_user.c | 3 +-
.../net/virtio/virtio_user/virtio_user_dev.c | 3 +-
examples/cmdline/commands.c | 2 +-
examples/cmdline/parse_obj_list.c | 2 +-
examples/ethtool/lib/rte_ethtool.c | 8 ++---
examples/exception_path/main.c | 4 +--
examples/ip_pipeline/kni.c | 2 +-
examples/ip_pipeline/tap.c | 2 +-
examples/l2fwd-crypto/main.c | 4 +--
examples/l3fwd-power/main.c | 2 +-
.../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 +++--
examples/vm_power_manager/channel_manager.c | 7 ++--
examples/vm_power_manager/channel_monitor.c | 14 ++++----
lib/librte_acl/rte_acl.c | 3 +-
lib/librte_bbdev/rte_bbdev.c | 3 +-
lib/librte_cfgfile/rte_cfgfile.c | 22 ++++++------
lib/librte_cmdline/cmdline.c | 2 +-
lib/librte_cmdline/cmdline_parse.c | 5 +--
lib/librte_cmdline/cmdline_parse_num.c | 2 +-
lib/librte_compressdev/rte_compressdev.c | 5 +--
lib/librte_compressdev/rte_compressdev_pmd.c | 3 +-
lib/librte_cryptodev/rte_cryptodev.c | 4 +--
lib/librte_cryptodev/rte_cryptodev_pmd.c | 3 +-
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_options.c | 3 +-
lib/librte_eal/common/eal_common_tailqs.c | 2 +-
lib/librte_efd/rte_efd.c | 3 +-
lib/librte_ethdev/rte_ethdev.c | 6 ++--
lib/librte_eventdev/rte_eventdev.c | 4 +--
lib/librte_flow_classify/rte_flow_classify.c | 4 +--
lib/librte_hash/rte_cuckoo_hash.c | 2 +-
lib/librte_hash/rte_fbk_hash.c | 2 +-
lib/librte_jobstats/rte_jobstats.c | 3 +-
lib/librte_kni/rte_kni.c | 6 ++--
lib/librte_latencystats/rte_latencystats.c | 5 +--
lib/librte_lpm/rte_lpm.c | 4 +--
lib/librte_lpm/rte_lpm6.c | 2 +-
lib/librte_member/rte_member.c | 3 +-
lib/librte_mempool/rte_mempool.c | 2 +-
lib/librte_mempool/rte_mempool_ops.c | 3 +-
lib/librte_pdump/rte_pdump.c | 8 ++---
lib/librte_pipeline/rte_pipeline.c | 2 +-
lib/librte_power/power_acpi_cpufreq.c | 3 +-
lib/librte_power/power_pstate_cpufreq.c | 3 +-
lib/librte_rawdev/rte_rawdev.c | 3 +-
lib/librte_reorder/rte_reorder.c | 5 +--
lib/librte_ring/rte_ring.c | 2 +-
102 files changed, 302 insertions(+), 270 deletions(-)
create mode 100644 devtools/cocci/strlcpy-with-header.cocci
--
2.20.1
^ permalink raw reply [flat|nested] 32+ messages in thread
* [dpdk-dev] [PATCH 1/5] net/bonding: fix buffer length when printing strings
2019-04-03 14:45 [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying Bruce Richardson
2019-04-03 14:45 ` Bruce Richardson
@ 2019-04-03 14:45 ` Bruce Richardson
2019-04-03 14:45 ` Bruce Richardson
2019-04-03 15:47 ` Stephen Hemminger
2019-04-03 14:45 ` [dpdk-dev] [PATCH 2/5] devtools/cocci: make strlcpy replacement smarter Bruce Richardson
` (5 subsequent siblings)
7 siblings, 2 replies; 32+ messages in thread
From: Bruce Richardson @ 2019-04-03 14:45 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson, Declan Doherty, stable
Using the size of the source string is incorrect when printing using
snprintf. Instead pass in the buffer size to be used appropriately.
Fixes: 457ecf2953fc ("bond: add debug info for mode 6")
CC: Declan Doherty <declan.doherty@intel.com>
CC: stable@dpdk.org
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
drivers/net/bonding/rte_eth_bond_pmd.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c
index 58b6e4344..154257ffe 100644
--- a/drivers/net/bonding/rte_eth_bond_pmd.c
+++ b/drivers/net/bonding/rte_eth_bond_pmd.c
@@ -489,35 +489,31 @@ uint32_t burstnumberTX;
#ifdef RTE_LIBRTE_BOND_DEBUG_ALB
static void
-arp_op_name(uint16_t arp_op, char *buf)
+arp_op_name(uint16_t arp_op, char *buf, size_t buf_len)
{
switch (arp_op) {
case ARP_OP_REQUEST:
- snprintf(buf, sizeof("ARP Request"), "%s", "ARP Request");
+ snprintf(buf, buf_len, "%s", "ARP Request");
return;
case ARP_OP_REPLY:
- snprintf(buf, sizeof("ARP Reply"), "%s", "ARP Reply");
+ snprintf(buf, buf_len, "%s", "ARP Reply");
return;
case ARP_OP_REVREQUEST:
- snprintf(buf, sizeof("Reverse ARP Request"), "%s",
- "Reverse ARP Request");
+ snprintf(buf, buf_len, "%s", "Reverse ARP Request");
return;
case ARP_OP_REVREPLY:
- snprintf(buf, sizeof("Reverse ARP Reply"), "%s",
- "Reverse ARP Reply");
+ snprintf(buf, buf_len, "%s", "Reverse ARP Reply");
return;
case ARP_OP_INVREQUEST:
- snprintf(buf, sizeof("Peer Identify Request"), "%s",
- "Peer Identify Request");
+ snprintf(buf, buf_len, "%s", "Peer Identify Request");
return;
case ARP_OP_INVREPLY:
- snprintf(buf, sizeof("Peer Identify Reply"), "%s",
- "Peer Identify Reply");
+ snprintf(buf, buf_len, "%s", "Peer Identify Reply");
return;
default:
break;
}
- snprintf(buf, sizeof("Unknown"), "%s", "Unknown");
+ snprintf(buf, buf_len, "%s", "Unknown");
return;
}
#endif
@@ -621,7 +617,8 @@ mode6_debug(const char __attribute__((unused)) *info, struct ether_hdr *eth_h,
arp_h = (struct arp_hdr *)((char *)(eth_h + 1) + offset);
ipv4_addr_to_dot(arp_h->arp_data.arp_sip, src_ip, MaxIPv4String);
ipv4_addr_to_dot(arp_h->arp_data.arp_tip, dst_ip, MaxIPv4String);
- arp_op_name(rte_be_to_cpu_16(arp_h->arp_op), ArpOp);
+ arp_op_name(rte_be_to_cpu_16(arp_h->arp_op),
+ ArpOp, sizeof(ArpOp));
MODE6_DEBUG(buf, src_ip, dst_ip, eth_h, ArpOp, port, *burstnumber);
}
#endif
--
2.20.1
^ permalink raw reply [flat|nested] 32+ messages in thread
* [dpdk-dev] [PATCH 1/5] net/bonding: fix buffer length when printing strings
2019-04-03 14:45 ` [dpdk-dev] [PATCH 1/5] net/bonding: fix buffer length when printing strings Bruce Richardson
@ 2019-04-03 14:45 ` Bruce Richardson
2019-04-03 15:47 ` Stephen Hemminger
1 sibling, 0 replies; 32+ messages in thread
From: Bruce Richardson @ 2019-04-03 14:45 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson, Declan Doherty, stable
Using the size of the source string is incorrect when printing using
snprintf. Instead pass in the buffer size to be used appropriately.
Fixes: 457ecf2953fc ("bond: add debug info for mode 6")
CC: Declan Doherty <declan.doherty@intel.com>
CC: stable@dpdk.org
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
drivers/net/bonding/rte_eth_bond_pmd.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c
index 58b6e4344..154257ffe 100644
--- a/drivers/net/bonding/rte_eth_bond_pmd.c
+++ b/drivers/net/bonding/rte_eth_bond_pmd.c
@@ -489,35 +489,31 @@ uint32_t burstnumberTX;
#ifdef RTE_LIBRTE_BOND_DEBUG_ALB
static void
-arp_op_name(uint16_t arp_op, char *buf)
+arp_op_name(uint16_t arp_op, char *buf, size_t buf_len)
{
switch (arp_op) {
case ARP_OP_REQUEST:
- snprintf(buf, sizeof("ARP Request"), "%s", "ARP Request");
+ snprintf(buf, buf_len, "%s", "ARP Request");
return;
case ARP_OP_REPLY:
- snprintf(buf, sizeof("ARP Reply"), "%s", "ARP Reply");
+ snprintf(buf, buf_len, "%s", "ARP Reply");
return;
case ARP_OP_REVREQUEST:
- snprintf(buf, sizeof("Reverse ARP Request"), "%s",
- "Reverse ARP Request");
+ snprintf(buf, buf_len, "%s", "Reverse ARP Request");
return;
case ARP_OP_REVREPLY:
- snprintf(buf, sizeof("Reverse ARP Reply"), "%s",
- "Reverse ARP Reply");
+ snprintf(buf, buf_len, "%s", "Reverse ARP Reply");
return;
case ARP_OP_INVREQUEST:
- snprintf(buf, sizeof("Peer Identify Request"), "%s",
- "Peer Identify Request");
+ snprintf(buf, buf_len, "%s", "Peer Identify Request");
return;
case ARP_OP_INVREPLY:
- snprintf(buf, sizeof("Peer Identify Reply"), "%s",
- "Peer Identify Reply");
+ snprintf(buf, buf_len, "%s", "Peer Identify Reply");
return;
default:
break;
}
- snprintf(buf, sizeof("Unknown"), "%s", "Unknown");
+ snprintf(buf, buf_len, "%s", "Unknown");
return;
}
#endif
@@ -621,7 +617,8 @@ mode6_debug(const char __attribute__((unused)) *info, struct ether_hdr *eth_h,
arp_h = (struct arp_hdr *)((char *)(eth_h + 1) + offset);
ipv4_addr_to_dot(arp_h->arp_data.arp_sip, src_ip, MaxIPv4String);
ipv4_addr_to_dot(arp_h->arp_data.arp_tip, dst_ip, MaxIPv4String);
- arp_op_name(rte_be_to_cpu_16(arp_h->arp_op), ArpOp);
+ arp_op_name(rte_be_to_cpu_16(arp_h->arp_op),
+ ArpOp, sizeof(ArpOp));
MODE6_DEBUG(buf, src_ip, dst_ip, eth_h, ArpOp, port, *burstnumber);
}
#endif
--
2.20.1
^ permalink raw reply [flat|nested] 32+ messages in thread
* [dpdk-dev] [PATCH 2/5] devtools/cocci: make strlcpy replacement smarter
2019-04-03 14:45 [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying Bruce Richardson
2019-04-03 14:45 ` Bruce Richardson
2019-04-03 14:45 ` [dpdk-dev] [PATCH 1/5] net/bonding: fix buffer length when printing strings Bruce Richardson
@ 2019-04-03 14:45 ` Bruce Richardson
2019-04-03 14:45 ` Bruce Richardson
2019-04-03 14:45 ` [dpdk-dev] [PATCH 3/5] devtools/cocci: create safer version of strlcpy script Bruce Richardson
` (4 subsequent siblings)
7 siblings, 1 reply; 32+ messages in thread
From: Bruce Richardson @ 2019-04-03 14:45 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
The original coccinelle script worked by replacing instances of
snprintf(.."%s",...) with strlcpy(), but only where the source and dest
parameters were plain identifiers. Allowing expressions for those params
opens up a wide range of other possible changes.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
devtools/cocci/strlcpy.cocci | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/devtools/cocci/strlcpy.cocci b/devtools/cocci/strlcpy.cocci
index 335e27128..6f6beb697 100644
--- a/devtools/cocci/strlcpy.cocci
+++ b/devtools/cocci/strlcpy.cocci
@@ -1,6 +1,5 @@
@use_strlcpy@
-identifier src, dst;
-expression size;
+expression src, dst, size;
@@
(
- snprintf(dst, size, "%s", src)
--
2.20.1
^ permalink raw reply [flat|nested] 32+ messages in thread
* [dpdk-dev] [PATCH 2/5] devtools/cocci: make strlcpy replacement smarter
2019-04-03 14:45 ` [dpdk-dev] [PATCH 2/5] devtools/cocci: make strlcpy replacement smarter Bruce Richardson
@ 2019-04-03 14:45 ` Bruce Richardson
0 siblings, 0 replies; 32+ messages in thread
From: Bruce Richardson @ 2019-04-03 14:45 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
The original coccinelle script worked by replacing instances of
snprintf(.."%s",...) with strlcpy(), but only where the source and dest
parameters were plain identifiers. Allowing expressions for those params
opens up a wide range of other possible changes.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
devtools/cocci/strlcpy.cocci | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/devtools/cocci/strlcpy.cocci b/devtools/cocci/strlcpy.cocci
index 335e27128..6f6beb697 100644
--- a/devtools/cocci/strlcpy.cocci
+++ b/devtools/cocci/strlcpy.cocci
@@ -1,6 +1,5 @@
@use_strlcpy@
-identifier src, dst;
-expression size;
+expression src, dst, size;
@@
(
- snprintf(dst, size, "%s", src)
--
2.20.1
^ permalink raw reply [flat|nested] 32+ messages in thread
* [dpdk-dev] [PATCH 3/5] devtools/cocci: create safer version of strlcpy script
2019-04-03 14:45 [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying Bruce Richardson
` (2 preceding siblings ...)
2019-04-03 14:45 ` [dpdk-dev] [PATCH 2/5] devtools/cocci: make strlcpy replacement smarter Bruce Richardson
@ 2019-04-03 14:45 ` Bruce Richardson
2019-04-03 14:45 ` Bruce Richardson
2019-04-03 14:45 ` [dpdk-dev] [PATCH 4/5] replace snprintf with strlcpy without adding extra include Bruce Richardson
` (3 subsequent siblings)
7 siblings, 1 reply; 32+ messages in thread
From: Bruce Richardson @ 2019-04-03 14:45 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
The existing cocci script for coccinelle replaces all matching instances
of snprintf() with strlcpy() without regards to header inclusion. To allow
changes without build errors, we create a safer version of this script
that only makes changes when the rte_string_fns.h header is already
included.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
| 12 ++++++++++++
1 file changed, 12 insertions(+)
create mode 100644 devtools/cocci/strlcpy-with-header.cocci
--git a/devtools/cocci/strlcpy-with-header.cocci b/devtools/cocci/strlcpy-with-header.cocci
new file mode 100644
index 000000000..046cdbdad
--- /dev/null
+++ b/devtools/cocci/strlcpy-with-header.cocci
@@ -0,0 +1,12 @@
+@include@
+@@
+
+#include <rte_string_fns.h>
+
+@use_strlcpy depends on include@
+expression src, dst, size;
+@@
+(
+- snprintf(dst, size, "%s", src)
++ strlcpy(dst, src, size)
+)
--
2.20.1
^ permalink raw reply [flat|nested] 32+ messages in thread
* [dpdk-dev] [PATCH 3/5] devtools/cocci: create safer version of strlcpy script
2019-04-03 14:45 ` [dpdk-dev] [PATCH 3/5] devtools/cocci: create safer version of strlcpy script Bruce Richardson
@ 2019-04-03 14:45 ` Bruce Richardson
0 siblings, 0 replies; 32+ messages in thread
From: Bruce Richardson @ 2019-04-03 14:45 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
The existing cocci script for coccinelle replaces all matching instances
of snprintf() with strlcpy() without regards to header inclusion. To allow
changes without build errors, we create a safer version of this script
that only makes changes when the rte_string_fns.h header is already
included.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
| 12 ++++++++++++
1 file changed, 12 insertions(+)
create mode 100644 devtools/cocci/strlcpy-with-header.cocci
--git a/devtools/cocci/strlcpy-with-header.cocci b/devtools/cocci/strlcpy-with-header.cocci
new file mode 100644
index 000000000..046cdbdad
--- /dev/null
+++ b/devtools/cocci/strlcpy-with-header.cocci
@@ -0,0 +1,12 @@
+@include@
+@@
+
+#include <rte_string_fns.h>
+
+@use_strlcpy depends on include@
+expression src, dst, size;
+@@
+(
+- snprintf(dst, size, "%s", src)
++ strlcpy(dst, src, size)
+)
--
2.20.1
^ permalink raw reply [flat|nested] 32+ messages in thread
* [dpdk-dev] [PATCH 4/5] replace snprintf with strlcpy without adding extra include
2019-04-03 14:45 [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying Bruce Richardson
` (3 preceding siblings ...)
2019-04-03 14:45 ` [dpdk-dev] [PATCH 3/5] devtools/cocci: create safer version of strlcpy script Bruce Richardson
@ 2019-04-03 14:45 ` Bruce Richardson
2019-04-03 14:45 ` Bruce Richardson
2019-04-03 15:51 ` Stephen Hemminger
2019-04-03 14:45 ` [dpdk-dev] [PATCH 5/5] replace snprintf with strlcpy Bruce Richardson
` (2 subsequent siblings)
7 siblings, 2 replies; 32+ messages in thread
From: Bruce Richardson @ 2019-04-03 14:45 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
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 <bruce.richardson@intel.com>
---
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;
--
2.20.1
^ permalink raw reply [flat|nested] 32+ messages in thread
* [dpdk-dev] [PATCH 4/5] replace snprintf with strlcpy without adding extra include
2019-04-03 14:45 ` [dpdk-dev] [PATCH 4/5] replace snprintf with strlcpy without adding extra include Bruce Richardson
@ 2019-04-03 14:45 ` Bruce Richardson
2019-04-03 15:51 ` Stephen Hemminger
1 sibling, 0 replies; 32+ messages in thread
From: Bruce Richardson @ 2019-04-03 14:45 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
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 <bruce.richardson@intel.com>
---
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;
--
2.20.1
^ permalink raw reply [flat|nested] 32+ messages in thread
* [dpdk-dev] [PATCH 5/5] replace snprintf with strlcpy
2019-04-03 14:45 [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying Bruce Richardson
` (4 preceding siblings ...)
2019-04-03 14:45 ` [dpdk-dev] [PATCH 4/5] replace snprintf with strlcpy without adding extra include Bruce Richardson
@ 2019-04-03 14:45 ` Bruce Richardson
2019-04-03 14:45 ` Bruce Richardson
2019-04-03 14:57 ` [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying Wiles, Keith
2019-04-04 20:11 ` Thomas Monjalon
7 siblings, 1 reply; 32+ messages in thread
From: Bruce Richardson @ 2019-04-03 14:45 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
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>
---
app/test-acl/main.c | 3 +-
app/test-eventdev/evt_options.c | 3 +-
app/test-pmd/cmdline_flow.c | 13 +++----
app/test/test_table_acl.c | 11 +++---
drivers/bus/dpaa/base/fman/of.c | 7 ++--
drivers/bus/pci/linux/pci_uio.c | 3 +-
.../crypto/aesni_mb/rte_aesni_mb_pmd_ops.c | 3 +-
.../aesni_mb/rte_aesni_mb_pmd_ops_compat.c | 3 +-
drivers/crypto/ccp/rte_ccp_pmd.c | 6 ++--
.../scheduler/rte_cryptodev_scheduler.c | 8 ++---
drivers/event/opdl/opdl_ring.c | 3 +-
drivers/net/af_packet/rte_eth_af_packet.c | 5 +--
drivers/net/ark/ark_pktchkr.c | 3 +-
drivers/net/ark/ark_pktgen.c | 3 +-
drivers/net/atlantic/atl_ethdev.c | 5 +--
drivers/net/bnx2x/bnx2x_ethdev.c | 8 ++---
drivers/net/bnxt/bnxt_stats.c | 36 +++++++++----------
drivers/net/dpaa/dpaa_ethdev.c | 8 ++---
drivers/net/e1000/igb_ethdev.c | 17 ++++-----
drivers/net/ena/ena_ethdev.c | 11 +++---
drivers/net/failsafe/failsafe_eal.c | 6 ++--
drivers/net/i40e/rte_pmd_i40e.c | 5 +--
drivers/net/ice/ice_ethdev.c | 11 +++---
drivers/net/ixgbe/ixgbe_ethdev.c | 35 +++++++++---------
drivers/net/kni/rte_eth_kni.c | 3 +-
drivers/net/liquidio/lio_ethdev.c | 5 +--
drivers/net/mvneta/mvneta_ethdev.c | 3 +-
drivers/net/mvpp2/mrvl_ethdev.c | 5 +--
drivers/net/qede/qede_ethdev.c | 22 ++++++------
drivers/net/virtio/virtio_user/vhost_user.c | 3 +-
.../net/virtio/virtio_user/virtio_user_dev.c | 3 +-
examples/ethtool/lib/rte_ethtool.c | 8 ++---
examples/l2fwd-crypto/main.c | 4 +--
examples/vm_power_manager/channel_manager.c | 7 ++--
examples/vm_power_manager/channel_monitor.c | 14 ++++----
lib/librte_acl/rte_acl.c | 3 +-
lib/librte_bbdev/rte_bbdev.c | 3 +-
lib/librte_cfgfile/rte_cfgfile.c | 22 ++++++------
lib/librte_compressdev/rte_compressdev.c | 5 +--
lib/librte_compressdev/rte_compressdev_pmd.c | 3 +-
lib/librte_cryptodev/rte_cryptodev_pmd.c | 3 +-
lib/librte_eal/common/eal_common_options.c | 3 +-
lib/librte_efd/rte_efd.c | 3 +-
lib/librte_eventdev/rte_eventdev.c | 4 +--
lib/librte_flow_classify/rte_flow_classify.c | 4 +--
lib/librte_jobstats/rte_jobstats.c | 3 +-
lib/librte_latencystats/rte_latencystats.c | 5 +--
lib/librte_member/rte_member.c | 3 +-
lib/librte_mempool/rte_mempool_ops.c | 3 +-
lib/librte_power/power_acpi_cpufreq.c | 3 +-
lib/librte_power/power_pstate_cpufreq.c | 3 +-
lib/librte_rawdev/rte_rawdev.c | 3 +-
lib/librte_reorder/rte_reorder.c | 5 +--
53 files changed, 201 insertions(+), 173 deletions(-)
diff --git a/app/test-acl/main.c b/app/test-acl/main.c
index 648525af5..b80179417 100644
--- a/app/test-acl/main.c
+++ b/app/test-acl/main.c
@@ -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
diff --git a/app/test-eventdev/evt_options.c b/app/test-eventdev/evt_options.c
index cfa43a165..cb95a32b8 100644
--- a/app/test-eventdev/evt_options.c
+++ b/app/test-eventdev/evt_options.c
@@ -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>
@@ -110,7 +111,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;
}
diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 36659a64a..1c83bc9bc 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -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
diff --git a/app/test/test_table_acl.c b/app/test/test_table_acl.c
index 33e2f6ee6..22136a396 100644
--- a/app/test/test_table_acl.c
+++ b/app/test/test_table_acl.c
@@ -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);
diff --git a/drivers/bus/dpaa/base/fman/of.c b/drivers/bus/dpaa/base/fman/of.c
index a7f3174e4..1e97be54e 100644
--- a/drivers/bus/dpaa/base/fman/of.c
+++ b/drivers/bus/dpaa/base/fman/of.c
@@ -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);
diff --git a/drivers/bus/pci/linux/pci_uio.c b/drivers/bus/pci/linux/pci_uio.c
index 09ecbb7aa..65f4896b9 100644
--- a/drivers/bus/pci/linux/pci_uio.c
+++ b/drivers/bus/pci/linux/pci_uio.c
@@ -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;
diff --git a/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops.c b/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops.c
index 3a8374ef3..8d15b99d4 100644
--- a/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops.c
+++ b/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops.c
@@ -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;
diff --git a/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops_compat.c b/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops_compat.c
index 79a38b25e..379a0c003 100644
--- a/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops_compat.c
+++ b/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops_compat.c
@@ -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>
@@ -565,7 +566,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;
diff --git a/drivers/crypto/ccp/rte_ccp_pmd.c b/drivers/crypto/ccp/rte_ccp_pmd.c
index b4bb5528f..4810d799c 100644
--- a/drivers/crypto/ccp/rte_ccp_pmd.c
+++ b/drivers/crypto/ccp/rte_ccp_pmd.c
@@ -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,
diff --git a/drivers/crypto/scheduler/rte_cryptodev_scheduler.c b/drivers/crypto/scheduler/rte_cryptodev_scheduler.c
index a21428606..1fef88f11 100644
--- a/drivers/crypto/scheduler/rte_cryptodev_scheduler.c
+++ b/drivers/crypto/scheduler/rte_cryptodev_scheduler.c
@@ -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;
diff --git a/drivers/event/opdl/opdl_ring.c b/drivers/event/opdl/opdl_ring.c
index 8aca481c9..e988f1cb2 100644
--- a/drivers/event/opdl/opdl_ring.c
+++ b/drivers/event/opdl/opdl_ring.c
@@ -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;
diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index 264cfc08f..99e13fe48 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -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;
diff --git a/drivers/net/ark/ark_pktchkr.c b/drivers/net/ark/ark_pktchkr.c
index c21003a04..ef861eea3 100644
--- a/drivers/net/ark/ark_pktchkr.c
+++ b/drivers/net/ark/ark_pktchkr.c
@@ -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;
diff --git a/drivers/net/ark/ark_pktgen.c b/drivers/net/ark/ark_pktgen.c
index 2a2b428e2..2cae252d6 100644
--- a/drivers/net/ark/ark_pktgen.c
+++ b/drivers/net/ark/ark_pktgen.c
@@ -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;
diff --git a/drivers/net/atlantic/atl_ethdev.c b/drivers/net/atlantic/atl_ethdev.c
index 5c62d137b..8327863cd 100644
--- a/drivers/net/atlantic/atl_ethdev.c
+++ b/drivers/net/atlantic/atl_ethdev.c
@@ -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;
}
diff --git a/drivers/net/bnx2x/bnx2x_ethdev.c b/drivers/net/bnx2x/bnx2x_ethdev.c
index cc7816dd5..1f2eb92b7 100644
--- a/drivers/net/bnx2x/bnx2x_ethdev.c
+++ b/drivers/net/bnx2x/bnx2x_ethdev.c
@@ -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;
}
diff --git a/drivers/net/bnxt/bnxt_stats.c b/drivers/net/bnxt/bnxt_stats.c
index c16bf99da..cae3b9ea2 100644
--- a/drivers/net/bnxt/bnxt_stats.c
+++ b/drivers/net/bnxt/bnxt_stats.c
@@ -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++;
}
diff --git a/drivers/net/dpaa/dpaa_ethdev.c b/drivers/net/dpaa/dpaa_ethdev.c
index b1fac8fa7..2e043feb2 100644
--- a/drivers/net/dpaa/dpaa_ethdev.c
+++ b/drivers/net/dpaa/dpaa_ethdev.c
@@ -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;
}
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index b897e8ad4..d3a8f5bf4 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -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;
}
diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c
index 08b1ab195..a55b4a719 100644
--- a/drivers/net/ena/ena_ethdev.c
+++ b/drivers/net/ena/ena_ethdev.c
@@ -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) |
diff --git a/drivers/net/failsafe/failsafe_eal.c b/drivers/net/failsafe/failsafe_eal.c
index 74fd8e97c..820a915f7 100644
--- a/drivers/net/failsafe/failsafe_eal.c
+++ b/drivers/net/failsafe/failsafe_eal.c
@@ -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"
diff --git a/drivers/net/i40e/rte_pmd_i40e.c b/drivers/net/i40e/rte_pmd_i40e.c
index c49c872b6..7ae78e426 100644
--- a/drivers/net/i40e/rte_pmd_i40e.c
+++ b/drivers/net/i40e/rte_pmd_i40e.c
@@ -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];
}
diff --git a/drivers/net/ice/ice_ethdev.c b/drivers/net/ice/ice_ethdev.c
index 1482cedb5..a06ebdadf 100644
--- a/drivers/net/ice/ice_ethdev.c
+++ b/drivers/net/ice/ice_ethdev.c
@@ -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++;
}
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index feec85634..b1be0c8b0 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -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;
}
diff --git a/drivers/net/kni/rte_eth_kni.c b/drivers/net/kni/rte_eth_kni.c
index 5e0222423..89f44737c 100644
--- a/drivers/net/kni/rte_eth_kni.c
+++ b/drivers/net/kni/rte_eth_kni.c
@@ -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 =
diff --git a/drivers/net/liquidio/lio_ethdev.c b/drivers/net/liquidio/lio_ethdev.c
index d13ab06c0..c9cabd65a 100644
--- a/drivers/net/liquidio/lio_ethdev.c
+++ b/drivers/net/liquidio/lio_ethdev.c
@@ -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);
diff --git a/drivers/net/mvneta/mvneta_ethdev.c b/drivers/net/mvneta/mvneta_ethdev.c
index 2d7666454..8923a1634 100644
--- a/drivers/net/mvneta/mvneta_ethdev.c
+++ b/drivers/net/mvneta/mvneta_ethdev.c
@@ -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;
diff --git a/drivers/net/mvpp2/mrvl_ethdev.c b/drivers/net/mvpp2/mrvl_ethdev.c
index ab4c14e51..ce52f0901 100644
--- a/drivers/net/mvpp2/mrvl_ethdev.c
+++ b/drivers/net/mvpp2/mrvl_ethdev.c
@@ -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;
}
diff --git a/drivers/net/qede/qede_ethdev.c b/drivers/net/qede/qede_ethdev.c
index 0b2f305e1..b2fd2fd90 100644
--- a/drivers/net/qede/qede_ethdev.c
+++ b/drivers/net/qede/qede_ethdev.c
@@ -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++;
}
}
diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c
index 2c6eba0a6..827a48ad6 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -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;
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index b004bc13a..8e420bcbc 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -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 */
diff --git a/examples/ethtool/lib/rte_ethtool.c b/examples/ethtool/lib/rte_ethtool.c
index e6a2e88c7..bf10139e7 100644
--- a/examples/ethtool/lib/rte_ethtool.c
+++ b/examples/ethtool/lib/rte_ethtool.c
@@ -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);
diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index 9982f07e9..06517b471 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -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;
}
diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c
index 09bfa5c0d..0187f79ab 100644
--- a/examples/vm_power_manager/channel_manager.c
+++ b/examples/vm_power_manager/channel_manager.c
@@ -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;
diff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c
index 7892d75de..74df0fe20 100644
--- a/examples/vm_power_manager/channel_monitor.c
+++ b/examples/vm_power_manager/channel_monitor.c
@@ -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")) {
diff --git a/lib/librte_acl/rte_acl.c b/lib/librte_acl/rte_acl.c
index db7d3221e..c436a9bfd 100644
--- a/lib/librte_acl/rte_acl.c
+++ b/lib/librte_acl/rte_acl.c
@@ -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;
diff --git a/lib/librte_bbdev/rte_bbdev.c b/lib/librte_bbdev/rte_bbdev.c
index c4cc18d98..a3ab5d973 100644
--- a/lib/librte_bbdev/rte_bbdev.c
+++ b/lib/librte_bbdev/rte_bbdev.c
@@ -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;
diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index 7d8c941ea..6110dba76 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -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 =
§ion->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;
diff --git a/lib/librte_compressdev/rte_compressdev.c b/lib/librte_compressdev/rte_compressdev.c
index 338134bdf..afba584c9 100644
--- a/lib/librte_compressdev/rte_compressdev.c
+++ b/lib/librte_compressdev/rte_compressdev.c
@@ -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;
diff --git a/lib/librte_compressdev/rte_compressdev_pmd.c b/lib/librte_compressdev/rte_compressdev_pmd.c
index 95beb26ab..cc51d69c8 100644
--- a/lib/librte_compressdev/rte_compressdev_pmd.c
+++ b/lib/librte_compressdev/rte_compressdev_pmd.c
@@ -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;
diff --git a/lib/librte_cryptodev/rte_cryptodev_pmd.c b/lib/librte_cryptodev/rte_cryptodev_pmd.c
index f03bdbd5e..091200412 100644
--- a/lib/librte_cryptodev/rte_cryptodev_pmd.c
+++ b/lib/librte_cryptodev/rte_cryptodev_pmd.c
@@ -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;
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 8dcfeb9b2..0c91024c4 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -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);
diff --git a/lib/librte_efd/rte_efd.c b/lib/librte_efd/rte_efd.c
index 1a97ece05..14e493bc3 100644
--- a/lib/librte_efd/rte_efd.c
+++ b/lib/librte_efd/rte_efd.c
@@ -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",
diff --git a/lib/librte_eventdev/rte_eventdev.c b/lib/librte_eventdev/rte_eventdev.c
index 4d4f07919..3bd571a87 100644
--- a/lib/librte_eventdev/rte_eventdev.c
+++ b/lib/librte_eventdev/rte_eventdev.c
@@ -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;
diff --git a/lib/librte_flow_classify/rte_flow_classify.c b/lib/librte_flow_classify/rte_flow_classify.c
index fb652a2b7..24f7f7aa0 100644
--- a/lib/librte_flow_classify/rte_flow_classify.c
+++ b/lib/librte_flow_classify/rte_flow_classify.c
@@ -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;
diff --git a/lib/librte_jobstats/rte_jobstats.c b/lib/librte_jobstats/rte_jobstats.c
index b64bc53bb..9b8fde5d5 100644
--- a/lib/librte_jobstats/rte_jobstats.c
+++ b/lib/librte_jobstats/rte_jobstats.c
@@ -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;
diff --git a/lib/librte_latencystats/rte_latencystats.c b/lib/librte_latencystats/rte_latencystats.c
index 5715549e4..06c62831b 100644
--- a/lib/librte_latencystats/rte_latencystats.c
+++ b/lib/librte_latencystats/rte_latencystats.c
@@ -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;
}
diff --git a/lib/librte_member/rte_member.c b/lib/librte_member/rte_member.c
index 702c01d3b..fd228f4ba 100644
--- a/lib/librte_member/rte_member.c
+++ b/lib/librte_member/rte_member.c
@@ -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;
diff --git a/lib/librte_mempool/rte_mempool_ops.c b/lib/librte_mempool/rte_mempool_ops.c
index a27e1fa51..e02eb702c 100644
--- a/lib/librte_mempool/rte_mempool_ops.c
+++ b/lib/librte_mempool/rte_mempool_ops.c
@@ -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;
diff --git a/lib/librte_power/power_acpi_cpufreq.c b/lib/librte_power/power_acpi_cpufreq.c
index 49325d0e0..5672c594e 100644
--- a/lib/librte_power/power_acpi_cpufreq.c
+++ b/lib/librte_power/power_acpi_cpufreq.c
@@ -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);
diff --git a/lib/librte_power/power_pstate_cpufreq.c b/lib/librte_power/power_pstate_cpufreq.c
index 61ff8dbb0..336c13869 100644
--- a/lib/librte_power/power_pstate_cpufreq.c
+++ b/lib/librte_power/power_pstate_cpufreq.c
@@ -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);
diff --git a/lib/librte_rawdev/rte_rawdev.c b/lib/librte_rawdev/rte_rawdev.c
index 9f1e3592d..2b2f45d7c 100644
--- a/lib/librte_rawdev/rte_rawdev.c
+++ b/lib/librte_rawdev/rte_rawdev.c
@@ -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++;
diff --git a/lib/librte_reorder/rte_reorder.c b/lib/librte_reorder/rte_reorder.c
index ecf539d22..b15328b2e 100644
--- a/lib/librte_reorder/rte_reorder.c
+++ b/lib/librte_reorder/rte_reorder.c
@@ -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);
}
--
2.20.1
^ permalink raw reply [flat|nested] 32+ messages in thread
* [dpdk-dev] [PATCH 5/5] replace snprintf with strlcpy
2019-04-03 14:45 ` [dpdk-dev] [PATCH 5/5] replace snprintf with strlcpy Bruce Richardson
@ 2019-04-03 14:45 ` Bruce Richardson
0 siblings, 0 replies; 32+ messages in thread
From: Bruce Richardson @ 2019-04-03 14:45 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
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>
---
app/test-acl/main.c | 3 +-
app/test-eventdev/evt_options.c | 3 +-
app/test-pmd/cmdline_flow.c | 13 +++----
app/test/test_table_acl.c | 11 +++---
drivers/bus/dpaa/base/fman/of.c | 7 ++--
drivers/bus/pci/linux/pci_uio.c | 3 +-
.../crypto/aesni_mb/rte_aesni_mb_pmd_ops.c | 3 +-
.../aesni_mb/rte_aesni_mb_pmd_ops_compat.c | 3 +-
drivers/crypto/ccp/rte_ccp_pmd.c | 6 ++--
.../scheduler/rte_cryptodev_scheduler.c | 8 ++---
drivers/event/opdl/opdl_ring.c | 3 +-
drivers/net/af_packet/rte_eth_af_packet.c | 5 +--
drivers/net/ark/ark_pktchkr.c | 3 +-
drivers/net/ark/ark_pktgen.c | 3 +-
drivers/net/atlantic/atl_ethdev.c | 5 +--
drivers/net/bnx2x/bnx2x_ethdev.c | 8 ++---
drivers/net/bnxt/bnxt_stats.c | 36 +++++++++----------
drivers/net/dpaa/dpaa_ethdev.c | 8 ++---
drivers/net/e1000/igb_ethdev.c | 17 ++++-----
drivers/net/ena/ena_ethdev.c | 11 +++---
drivers/net/failsafe/failsafe_eal.c | 6 ++--
drivers/net/i40e/rte_pmd_i40e.c | 5 +--
drivers/net/ice/ice_ethdev.c | 11 +++---
drivers/net/ixgbe/ixgbe_ethdev.c | 35 +++++++++---------
drivers/net/kni/rte_eth_kni.c | 3 +-
drivers/net/liquidio/lio_ethdev.c | 5 +--
drivers/net/mvneta/mvneta_ethdev.c | 3 +-
drivers/net/mvpp2/mrvl_ethdev.c | 5 +--
drivers/net/qede/qede_ethdev.c | 22 ++++++------
drivers/net/virtio/virtio_user/vhost_user.c | 3 +-
.../net/virtio/virtio_user/virtio_user_dev.c | 3 +-
examples/ethtool/lib/rte_ethtool.c | 8 ++---
examples/l2fwd-crypto/main.c | 4 +--
examples/vm_power_manager/channel_manager.c | 7 ++--
examples/vm_power_manager/channel_monitor.c | 14 ++++----
lib/librte_acl/rte_acl.c | 3 +-
lib/librte_bbdev/rte_bbdev.c | 3 +-
lib/librte_cfgfile/rte_cfgfile.c | 22 ++++++------
lib/librte_compressdev/rte_compressdev.c | 5 +--
lib/librte_compressdev/rte_compressdev_pmd.c | 3 +-
lib/librte_cryptodev/rte_cryptodev_pmd.c | 3 +-
lib/librte_eal/common/eal_common_options.c | 3 +-
lib/librte_efd/rte_efd.c | 3 +-
lib/librte_eventdev/rte_eventdev.c | 4 +--
lib/librte_flow_classify/rte_flow_classify.c | 4 +--
lib/librte_jobstats/rte_jobstats.c | 3 +-
lib/librte_latencystats/rte_latencystats.c | 5 +--
lib/librte_member/rte_member.c | 3 +-
lib/librte_mempool/rte_mempool_ops.c | 3 +-
lib/librte_power/power_acpi_cpufreq.c | 3 +-
lib/librte_power/power_pstate_cpufreq.c | 3 +-
lib/librte_rawdev/rte_rawdev.c | 3 +-
lib/librte_reorder/rte_reorder.c | 5 +--
53 files changed, 201 insertions(+), 173 deletions(-)
diff --git a/app/test-acl/main.c b/app/test-acl/main.c
index 648525af5..b80179417 100644
--- a/app/test-acl/main.c
+++ b/app/test-acl/main.c
@@ -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
diff --git a/app/test-eventdev/evt_options.c b/app/test-eventdev/evt_options.c
index cfa43a165..cb95a32b8 100644
--- a/app/test-eventdev/evt_options.c
+++ b/app/test-eventdev/evt_options.c
@@ -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>
@@ -110,7 +111,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;
}
diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 36659a64a..1c83bc9bc 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -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
diff --git a/app/test/test_table_acl.c b/app/test/test_table_acl.c
index 33e2f6ee6..22136a396 100644
--- a/app/test/test_table_acl.c
+++ b/app/test/test_table_acl.c
@@ -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);
diff --git a/drivers/bus/dpaa/base/fman/of.c b/drivers/bus/dpaa/base/fman/of.c
index a7f3174e4..1e97be54e 100644
--- a/drivers/bus/dpaa/base/fman/of.c
+++ b/drivers/bus/dpaa/base/fman/of.c
@@ -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);
diff --git a/drivers/bus/pci/linux/pci_uio.c b/drivers/bus/pci/linux/pci_uio.c
index 09ecbb7aa..65f4896b9 100644
--- a/drivers/bus/pci/linux/pci_uio.c
+++ b/drivers/bus/pci/linux/pci_uio.c
@@ -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;
diff --git a/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops.c b/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops.c
index 3a8374ef3..8d15b99d4 100644
--- a/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops.c
+++ b/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops.c
@@ -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;
diff --git a/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops_compat.c b/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops_compat.c
index 79a38b25e..379a0c003 100644
--- a/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops_compat.c
+++ b/drivers/crypto/aesni_mb/rte_aesni_mb_pmd_ops_compat.c
@@ -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>
@@ -565,7 +566,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;
diff --git a/drivers/crypto/ccp/rte_ccp_pmd.c b/drivers/crypto/ccp/rte_ccp_pmd.c
index b4bb5528f..4810d799c 100644
--- a/drivers/crypto/ccp/rte_ccp_pmd.c
+++ b/drivers/crypto/ccp/rte_ccp_pmd.c
@@ -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,
diff --git a/drivers/crypto/scheduler/rte_cryptodev_scheduler.c b/drivers/crypto/scheduler/rte_cryptodev_scheduler.c
index a21428606..1fef88f11 100644
--- a/drivers/crypto/scheduler/rte_cryptodev_scheduler.c
+++ b/drivers/crypto/scheduler/rte_cryptodev_scheduler.c
@@ -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;
diff --git a/drivers/event/opdl/opdl_ring.c b/drivers/event/opdl/opdl_ring.c
index 8aca481c9..e988f1cb2 100644
--- a/drivers/event/opdl/opdl_ring.c
+++ b/drivers/event/opdl/opdl_ring.c
@@ -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;
diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index 264cfc08f..99e13fe48 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -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;
diff --git a/drivers/net/ark/ark_pktchkr.c b/drivers/net/ark/ark_pktchkr.c
index c21003a04..ef861eea3 100644
--- a/drivers/net/ark/ark_pktchkr.c
+++ b/drivers/net/ark/ark_pktchkr.c
@@ -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;
diff --git a/drivers/net/ark/ark_pktgen.c b/drivers/net/ark/ark_pktgen.c
index 2a2b428e2..2cae252d6 100644
--- a/drivers/net/ark/ark_pktgen.c
+++ b/drivers/net/ark/ark_pktgen.c
@@ -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;
diff --git a/drivers/net/atlantic/atl_ethdev.c b/drivers/net/atlantic/atl_ethdev.c
index 5c62d137b..8327863cd 100644
--- a/drivers/net/atlantic/atl_ethdev.c
+++ b/drivers/net/atlantic/atl_ethdev.c
@@ -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;
}
diff --git a/drivers/net/bnx2x/bnx2x_ethdev.c b/drivers/net/bnx2x/bnx2x_ethdev.c
index cc7816dd5..1f2eb92b7 100644
--- a/drivers/net/bnx2x/bnx2x_ethdev.c
+++ b/drivers/net/bnx2x/bnx2x_ethdev.c
@@ -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;
}
diff --git a/drivers/net/bnxt/bnxt_stats.c b/drivers/net/bnxt/bnxt_stats.c
index c16bf99da..cae3b9ea2 100644
--- a/drivers/net/bnxt/bnxt_stats.c
+++ b/drivers/net/bnxt/bnxt_stats.c
@@ -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++;
}
diff --git a/drivers/net/dpaa/dpaa_ethdev.c b/drivers/net/dpaa/dpaa_ethdev.c
index b1fac8fa7..2e043feb2 100644
--- a/drivers/net/dpaa/dpaa_ethdev.c
+++ b/drivers/net/dpaa/dpaa_ethdev.c
@@ -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;
}
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index b897e8ad4..d3a8f5bf4 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -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;
}
diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c
index 08b1ab195..a55b4a719 100644
--- a/drivers/net/ena/ena_ethdev.c
+++ b/drivers/net/ena/ena_ethdev.c
@@ -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) |
diff --git a/drivers/net/failsafe/failsafe_eal.c b/drivers/net/failsafe/failsafe_eal.c
index 74fd8e97c..820a915f7 100644
--- a/drivers/net/failsafe/failsafe_eal.c
+++ b/drivers/net/failsafe/failsafe_eal.c
@@ -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"
diff --git a/drivers/net/i40e/rte_pmd_i40e.c b/drivers/net/i40e/rte_pmd_i40e.c
index c49c872b6..7ae78e426 100644
--- a/drivers/net/i40e/rte_pmd_i40e.c
+++ b/drivers/net/i40e/rte_pmd_i40e.c
@@ -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];
}
diff --git a/drivers/net/ice/ice_ethdev.c b/drivers/net/ice/ice_ethdev.c
index 1482cedb5..a06ebdadf 100644
--- a/drivers/net/ice/ice_ethdev.c
+++ b/drivers/net/ice/ice_ethdev.c
@@ -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++;
}
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index feec85634..b1be0c8b0 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -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;
}
diff --git a/drivers/net/kni/rte_eth_kni.c b/drivers/net/kni/rte_eth_kni.c
index 5e0222423..89f44737c 100644
--- a/drivers/net/kni/rte_eth_kni.c
+++ b/drivers/net/kni/rte_eth_kni.c
@@ -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 =
diff --git a/drivers/net/liquidio/lio_ethdev.c b/drivers/net/liquidio/lio_ethdev.c
index d13ab06c0..c9cabd65a 100644
--- a/drivers/net/liquidio/lio_ethdev.c
+++ b/drivers/net/liquidio/lio_ethdev.c
@@ -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);
diff --git a/drivers/net/mvneta/mvneta_ethdev.c b/drivers/net/mvneta/mvneta_ethdev.c
index 2d7666454..8923a1634 100644
--- a/drivers/net/mvneta/mvneta_ethdev.c
+++ b/drivers/net/mvneta/mvneta_ethdev.c
@@ -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;
diff --git a/drivers/net/mvpp2/mrvl_ethdev.c b/drivers/net/mvpp2/mrvl_ethdev.c
index ab4c14e51..ce52f0901 100644
--- a/drivers/net/mvpp2/mrvl_ethdev.c
+++ b/drivers/net/mvpp2/mrvl_ethdev.c
@@ -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;
}
diff --git a/drivers/net/qede/qede_ethdev.c b/drivers/net/qede/qede_ethdev.c
index 0b2f305e1..b2fd2fd90 100644
--- a/drivers/net/qede/qede_ethdev.c
+++ b/drivers/net/qede/qede_ethdev.c
@@ -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++;
}
}
diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c
index 2c6eba0a6..827a48ad6 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -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;
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index b004bc13a..8e420bcbc 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -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 */
diff --git a/examples/ethtool/lib/rte_ethtool.c b/examples/ethtool/lib/rte_ethtool.c
index e6a2e88c7..bf10139e7 100644
--- a/examples/ethtool/lib/rte_ethtool.c
+++ b/examples/ethtool/lib/rte_ethtool.c
@@ -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);
diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index 9982f07e9..06517b471 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -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;
}
diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c
index 09bfa5c0d..0187f79ab 100644
--- a/examples/vm_power_manager/channel_manager.c
+++ b/examples/vm_power_manager/channel_manager.c
@@ -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;
diff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c
index 7892d75de..74df0fe20 100644
--- a/examples/vm_power_manager/channel_monitor.c
+++ b/examples/vm_power_manager/channel_monitor.c
@@ -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")) {
diff --git a/lib/librte_acl/rte_acl.c b/lib/librte_acl/rte_acl.c
index db7d3221e..c436a9bfd 100644
--- a/lib/librte_acl/rte_acl.c
+++ b/lib/librte_acl/rte_acl.c
@@ -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;
diff --git a/lib/librte_bbdev/rte_bbdev.c b/lib/librte_bbdev/rte_bbdev.c
index c4cc18d98..a3ab5d973 100644
--- a/lib/librte_bbdev/rte_bbdev.c
+++ b/lib/librte_bbdev/rte_bbdev.c
@@ -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;
diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index 7d8c941ea..6110dba76 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -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 =
§ion->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;
diff --git a/lib/librte_compressdev/rte_compressdev.c b/lib/librte_compressdev/rte_compressdev.c
index 338134bdf..afba584c9 100644
--- a/lib/librte_compressdev/rte_compressdev.c
+++ b/lib/librte_compressdev/rte_compressdev.c
@@ -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;
diff --git a/lib/librte_compressdev/rte_compressdev_pmd.c b/lib/librte_compressdev/rte_compressdev_pmd.c
index 95beb26ab..cc51d69c8 100644
--- a/lib/librte_compressdev/rte_compressdev_pmd.c
+++ b/lib/librte_compressdev/rte_compressdev_pmd.c
@@ -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;
diff --git a/lib/librte_cryptodev/rte_cryptodev_pmd.c b/lib/librte_cryptodev/rte_cryptodev_pmd.c
index f03bdbd5e..091200412 100644
--- a/lib/librte_cryptodev/rte_cryptodev_pmd.c
+++ b/lib/librte_cryptodev/rte_cryptodev_pmd.c
@@ -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;
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 8dcfeb9b2..0c91024c4 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -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);
diff --git a/lib/librte_efd/rte_efd.c b/lib/librte_efd/rte_efd.c
index 1a97ece05..14e493bc3 100644
--- a/lib/librte_efd/rte_efd.c
+++ b/lib/librte_efd/rte_efd.c
@@ -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",
diff --git a/lib/librte_eventdev/rte_eventdev.c b/lib/librte_eventdev/rte_eventdev.c
index 4d4f07919..3bd571a87 100644
--- a/lib/librte_eventdev/rte_eventdev.c
+++ b/lib/librte_eventdev/rte_eventdev.c
@@ -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;
diff --git a/lib/librte_flow_classify/rte_flow_classify.c b/lib/librte_flow_classify/rte_flow_classify.c
index fb652a2b7..24f7f7aa0 100644
--- a/lib/librte_flow_classify/rte_flow_classify.c
+++ b/lib/librte_flow_classify/rte_flow_classify.c
@@ -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;
diff --git a/lib/librte_jobstats/rte_jobstats.c b/lib/librte_jobstats/rte_jobstats.c
index b64bc53bb..9b8fde5d5 100644
--- a/lib/librte_jobstats/rte_jobstats.c
+++ b/lib/librte_jobstats/rte_jobstats.c
@@ -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;
diff --git a/lib/librte_latencystats/rte_latencystats.c b/lib/librte_latencystats/rte_latencystats.c
index 5715549e4..06c62831b 100644
--- a/lib/librte_latencystats/rte_latencystats.c
+++ b/lib/librte_latencystats/rte_latencystats.c
@@ -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;
}
diff --git a/lib/librte_member/rte_member.c b/lib/librte_member/rte_member.c
index 702c01d3b..fd228f4ba 100644
--- a/lib/librte_member/rte_member.c
+++ b/lib/librte_member/rte_member.c
@@ -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;
diff --git a/lib/librte_mempool/rte_mempool_ops.c b/lib/librte_mempool/rte_mempool_ops.c
index a27e1fa51..e02eb702c 100644
--- a/lib/librte_mempool/rte_mempool_ops.c
+++ b/lib/librte_mempool/rte_mempool_ops.c
@@ -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;
diff --git a/lib/librte_power/power_acpi_cpufreq.c b/lib/librte_power/power_acpi_cpufreq.c
index 49325d0e0..5672c594e 100644
--- a/lib/librte_power/power_acpi_cpufreq.c
+++ b/lib/librte_power/power_acpi_cpufreq.c
@@ -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);
diff --git a/lib/librte_power/power_pstate_cpufreq.c b/lib/librte_power/power_pstate_cpufreq.c
index 61ff8dbb0..336c13869 100644
--- a/lib/librte_power/power_pstate_cpufreq.c
+++ b/lib/librte_power/power_pstate_cpufreq.c
@@ -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);
diff --git a/lib/librte_rawdev/rte_rawdev.c b/lib/librte_rawdev/rte_rawdev.c
index 9f1e3592d..2b2f45d7c 100644
--- a/lib/librte_rawdev/rte_rawdev.c
+++ b/lib/librte_rawdev/rte_rawdev.c
@@ -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++;
diff --git a/lib/librte_reorder/rte_reorder.c b/lib/librte_reorder/rte_reorder.c
index ecf539d22..b15328b2e 100644
--- a/lib/librte_reorder/rte_reorder.c
+++ b/lib/librte_reorder/rte_reorder.c
@@ -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);
}
--
2.20.1
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying
2019-04-03 14:45 [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying Bruce Richardson
` (5 preceding siblings ...)
2019-04-03 14:45 ` [dpdk-dev] [PATCH 5/5] replace snprintf with strlcpy Bruce Richardson
@ 2019-04-03 14:57 ` Wiles, Keith
2019-04-03 14:57 ` Wiles, Keith
` (2 more replies)
2019-04-04 20:11 ` Thomas Monjalon
7 siblings, 3 replies; 32+ messages in thread
From: Wiles, Keith @ 2019-04-03 14:57 UTC (permalink / raw)
To: Richardson, Bruce; +Cc: dev
> On Apr 3, 2019, at 9:45 AM, Bruce Richardson <bruce.richardson@intel.com> wrote:
>
> There are quite a few instances remaining in DPDK where snprintf is being
> used for string copying. These were not being picked up by our existing
> coccinelle script, but that can be fixed by editing the script and running
> it against our code. In the process a bug was found and fixed in the
> bonding pmd, where we were incorrectly specifiying the buffer length
> parameter to snprintf.
>
> The actual replacement was done in two phases - first replacing all
> instances where only the snprintf line in question needed changing, then
> fixing the other instances where we also needed to add in the header
> include. [Using two stages allowed the header addition to be automated too,
> since we had a list of files where every one needed the header inclusion]
>
>
> Bruce Richardson (5):
> net/bonding: fix buffer length when printing strings
> devtools/cocci: make strlcpy replacement smarter
> devtools/cocci: create safer version of strlcpy script
> replace snprintf with strlcpy without adding extra include
> replace snprintf with strlcpy
>
Should we not be testing the return values from strlcpy and snprintf, which means we need to create a macro or inline function. We could use a macro and only enable with DEBUG support if we think performance or code size if a problem.
I am surprised none of the tools are catching these types of problems.
Not to make Bruce do that change for this patch, but we need to look at it for a later patch IMO.
Regards,
Keith
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying
2019-04-03 14:57 ` [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying Wiles, Keith
@ 2019-04-03 14:57 ` Wiles, Keith
2019-04-03 15:13 ` Bruce Richardson
2019-04-03 15:27 ` Stephen Hemminger
2 siblings, 0 replies; 32+ messages in thread
From: Wiles, Keith @ 2019-04-03 14:57 UTC (permalink / raw)
To: Richardson, Bruce; +Cc: dev
> On Apr 3, 2019, at 9:45 AM, Bruce Richardson <bruce.richardson@intel.com> wrote:
>
> There are quite a few instances remaining in DPDK where snprintf is being
> used for string copying. These were not being picked up by our existing
> coccinelle script, but that can be fixed by editing the script and running
> it against our code. In the process a bug was found and fixed in the
> bonding pmd, where we were incorrectly specifiying the buffer length
> parameter to snprintf.
>
> The actual replacement was done in two phases - first replacing all
> instances where only the snprintf line in question needed changing, then
> fixing the other instances where we also needed to add in the header
> include. [Using two stages allowed the header addition to be automated too,
> since we had a list of files where every one needed the header inclusion]
>
>
> Bruce Richardson (5):
> net/bonding: fix buffer length when printing strings
> devtools/cocci: make strlcpy replacement smarter
> devtools/cocci: create safer version of strlcpy script
> replace snprintf with strlcpy without adding extra include
> replace snprintf with strlcpy
>
Should we not be testing the return values from strlcpy and snprintf, which means we need to create a macro or inline function. We could use a macro and only enable with DEBUG support if we think performance or code size if a problem.
I am surprised none of the tools are catching these types of problems.
Not to make Bruce do that change for this patch, but we need to look at it for a later patch IMO.
Regards,
Keith
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying
2019-04-03 14:57 ` [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying Wiles, Keith
2019-04-03 14:57 ` Wiles, Keith
@ 2019-04-03 15:13 ` Bruce Richardson
2019-04-03 15:13 ` Bruce Richardson
2019-04-03 15:27 ` Stephen Hemminger
2 siblings, 1 reply; 32+ messages in thread
From: Bruce Richardson @ 2019-04-03 15:13 UTC (permalink / raw)
To: Wiles, Keith; +Cc: dev
On Wed, Apr 03, 2019 at 03:57:49PM +0100, Wiles, Keith wrote:
>
>
> > On Apr 3, 2019, at 9:45 AM, Bruce Richardson <bruce.richardson@intel.com> wrote:
> >
> > There are quite a few instances remaining in DPDK where snprintf is being
> > used for string copying. These were not being picked up by our existing
> > coccinelle script, but that can be fixed by editing the script and running
> > it against our code. In the process a bug was found and fixed in the
> > bonding pmd, where we were incorrectly specifiying the buffer length
> > parameter to snprintf.
> >
> > The actual replacement was done in two phases - first replacing all
> > instances where only the snprintf line in question needed changing, then
> > fixing the other instances where we also needed to add in the header
> > include. [Using two stages allowed the header addition to be automated too,
> > since we had a list of files where every one needed the header inclusion]
> >
> >
> > Bruce Richardson (5):
> > net/bonding: fix buffer length when printing strings
> > devtools/cocci: make strlcpy replacement smarter
> > devtools/cocci: create safer version of strlcpy script
> > replace snprintf with strlcpy without adding extra include
> > replace snprintf with strlcpy
> >
>
> Should we not be testing the return values from strlcpy and snprintf, which means we need to create a macro or inline function. We could use a macro and only enable with DEBUG support if we think performance or code size if a problem.
>
Yes, I think in some/many cases we should be checking the return value, but
unfortunately I don't think it's the case that we always should or should
not do so. In some cases, truncation is fine. Therefore, I don't think an
automated solution can work here, and I don't see much point in wrapping
any of these functions in macros, since the action to take on truncation
probably varies from place to place.
> I am surprised none of the tools are catching these types of problems.
>
Yes. It would be useful to have a tool to flag this, so we can see under
what circumstances it may be a problem.
> Not to make Bruce do that change for this patch, but we need to look at it for a later patch IMO.
>
Phew! :-)
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying
2019-04-03 15:13 ` Bruce Richardson
@ 2019-04-03 15:13 ` Bruce Richardson
0 siblings, 0 replies; 32+ messages in thread
From: Bruce Richardson @ 2019-04-03 15:13 UTC (permalink / raw)
To: Wiles, Keith; +Cc: dev
On Wed, Apr 03, 2019 at 03:57:49PM +0100, Wiles, Keith wrote:
>
>
> > On Apr 3, 2019, at 9:45 AM, Bruce Richardson <bruce.richardson@intel.com> wrote:
> >
> > There are quite a few instances remaining in DPDK where snprintf is being
> > used for string copying. These were not being picked up by our existing
> > coccinelle script, but that can be fixed by editing the script and running
> > it against our code. In the process a bug was found and fixed in the
> > bonding pmd, where we were incorrectly specifiying the buffer length
> > parameter to snprintf.
> >
> > The actual replacement was done in two phases - first replacing all
> > instances where only the snprintf line in question needed changing, then
> > fixing the other instances where we also needed to add in the header
> > include. [Using two stages allowed the header addition to be automated too,
> > since we had a list of files where every one needed the header inclusion]
> >
> >
> > Bruce Richardson (5):
> > net/bonding: fix buffer length when printing strings
> > devtools/cocci: make strlcpy replacement smarter
> > devtools/cocci: create safer version of strlcpy script
> > replace snprintf with strlcpy without adding extra include
> > replace snprintf with strlcpy
> >
>
> Should we not be testing the return values from strlcpy and snprintf, which means we need to create a macro or inline function. We could use a macro and only enable with DEBUG support if we think performance or code size if a problem.
>
Yes, I think in some/many cases we should be checking the return value, but
unfortunately I don't think it's the case that we always should or should
not do so. In some cases, truncation is fine. Therefore, I don't think an
automated solution can work here, and I don't see much point in wrapping
any of these functions in macros, since the action to take on truncation
probably varies from place to place.
> I am surprised none of the tools are catching these types of problems.
>
Yes. It would be useful to have a tool to flag this, so we can see under
what circumstances it may be a problem.
> Not to make Bruce do that change for this patch, but we need to look at it for a later patch IMO.
>
Phew! :-)
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying
2019-04-03 14:57 ` [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying Wiles, Keith
2019-04-03 14:57 ` Wiles, Keith
2019-04-03 15:13 ` Bruce Richardson
@ 2019-04-03 15:27 ` Stephen Hemminger
2019-04-03 15:27 ` Stephen Hemminger
2 siblings, 1 reply; 32+ messages in thread
From: Stephen Hemminger @ 2019-04-03 15:27 UTC (permalink / raw)
To: Wiles, Keith; +Cc: Richardson, Bruce, dev
On Wed, 3 Apr 2019 14:57:49 +0000
"Wiles, Keith" <keith.wiles@intel.com> wrote:
> > On Apr 3, 2019, at 9:45 AM, Bruce Richardson <bruce.richardson@intel.com> wrote:
> >
> > There are quite a few instances remaining in DPDK where snprintf is being
> > used for string copying. These were not being picked up by our existing
> > coccinelle script, but that can be fixed by editing the script and running
> > it against our code. In the process a bug was found and fixed in the
> > bonding pmd, where we were incorrectly specifiying the buffer length
> > parameter to snprintf.
> >
> > The actual replacement was done in two phases - first replacing all
> > instances where only the snprintf line in question needed changing, then
> > fixing the other instances where we also needed to add in the header
> > include. [Using two stages allowed the header addition to be automated too,
> > since we had a list of files where every one needed the header inclusion]
> >
> >
> > Bruce Richardson (5):
> > net/bonding: fix buffer length when printing strings
> > devtools/cocci: make strlcpy replacement smarter
> > devtools/cocci: create safer version of strlcpy script
> > replace snprintf with strlcpy without adding extra include
> > replace snprintf with strlcpy
> >
>
> Should we not be testing the return values from strlcpy and snprintf, which means we need to create a macro or inline function. We could use a macro and only enable with DEBUG support if we think performance or code size if a problem.
>
> I am surprised none of the tools are catching these types of problems.
>
> Not to make Bruce do that change for this patch, but we need to look at it for a later patch IMO.
>
> Regards,
> Keith
>
In a lot of cases the error checking should be earlier in the input path.
Detecting overflow late in making a string is unhelpful. But rejecting
input where the name is too long to start with is safer and better.
It is one of those cases where static checkers tell you there is a
problem but the right solution is farther back in the code, not just
right where the error is reported.
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying
2019-04-03 15:27 ` Stephen Hemminger
@ 2019-04-03 15:27 ` Stephen Hemminger
0 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2019-04-03 15:27 UTC (permalink / raw)
To: Wiles, Keith; +Cc: Richardson, Bruce, dev
On Wed, 3 Apr 2019 14:57:49 +0000
"Wiles, Keith" <keith.wiles@intel.com> wrote:
> > On Apr 3, 2019, at 9:45 AM, Bruce Richardson <bruce.richardson@intel.com> wrote:
> >
> > There are quite a few instances remaining in DPDK where snprintf is being
> > used for string copying. These were not being picked up by our existing
> > coccinelle script, but that can be fixed by editing the script and running
> > it against our code. In the process a bug was found and fixed in the
> > bonding pmd, where we were incorrectly specifiying the buffer length
> > parameter to snprintf.
> >
> > The actual replacement was done in two phases - first replacing all
> > instances where only the snprintf line in question needed changing, then
> > fixing the other instances where we also needed to add in the header
> > include. [Using two stages allowed the header addition to be automated too,
> > since we had a list of files where every one needed the header inclusion]
> >
> >
> > Bruce Richardson (5):
> > net/bonding: fix buffer length when printing strings
> > devtools/cocci: make strlcpy replacement smarter
> > devtools/cocci: create safer version of strlcpy script
> > replace snprintf with strlcpy without adding extra include
> > replace snprintf with strlcpy
> >
>
> Should we not be testing the return values from strlcpy and snprintf, which means we need to create a macro or inline function. We could use a macro and only enable with DEBUG support if we think performance or code size if a problem.
>
> I am surprised none of the tools are catching these types of problems.
>
> Not to make Bruce do that change for this patch, but we need to look at it for a later patch IMO.
>
> Regards,
> Keith
>
In a lot of cases the error checking should be earlier in the input path.
Detecting overflow late in making a string is unhelpful. But rejecting
input where the name is too long to start with is safer and better.
It is one of those cases where static checkers tell you there is a
problem but the right solution is farther back in the code, not just
right where the error is reported.
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 1/5] net/bonding: fix buffer length when printing strings
2019-04-03 14:45 ` [dpdk-dev] [PATCH 1/5] net/bonding: fix buffer length when printing strings Bruce Richardson
2019-04-03 14:45 ` Bruce Richardson
@ 2019-04-03 15:47 ` Stephen Hemminger
2019-04-03 15:47 ` Stephen Hemminger
2019-04-03 15:51 ` Bruce Richardson
1 sibling, 2 replies; 32+ messages in thread
From: Stephen Hemminger @ 2019-04-03 15:47 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev, Declan Doherty, stable
On Wed, 3 Apr 2019 15:45:01 +0100
Bruce Richardson <bruce.richardson@intel.com> wrote:
>
> static void
> -arp_op_name(uint16_t arp_op, char *buf)
> +arp_op_name(uint16_t arp_op, char *buf, size_t buf_len)
> {
> switch (arp_op) {
> case ARP_OP_REQUEST:
> - snprintf(buf, sizeof("ARP Request"), "%s", "ARP Request");
> + snprintf(buf, buf_len, "%s", "ARP Request");
> return;
This should be strlcpy not snprintf
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 1/5] net/bonding: fix buffer length when printing strings
2019-04-03 15:47 ` Stephen Hemminger
@ 2019-04-03 15:47 ` Stephen Hemminger
2019-04-03 15:51 ` Bruce Richardson
1 sibling, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2019-04-03 15:47 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev, Declan Doherty, stable
On Wed, 3 Apr 2019 15:45:01 +0100
Bruce Richardson <bruce.richardson@intel.com> wrote:
>
> static void
> -arp_op_name(uint16_t arp_op, char *buf)
> +arp_op_name(uint16_t arp_op, char *buf, size_t buf_len)
> {
> switch (arp_op) {
> case ARP_OP_REQUEST:
> - snprintf(buf, sizeof("ARP Request"), "%s", "ARP Request");
> + snprintf(buf, buf_len, "%s", "ARP Request");
> return;
This should be strlcpy not snprintf
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 1/5] net/bonding: fix buffer length when printing strings
2019-04-03 15:47 ` Stephen Hemminger
2019-04-03 15:47 ` Stephen Hemminger
@ 2019-04-03 15:51 ` Bruce Richardson
2019-04-03 15:51 ` Bruce Richardson
2019-04-03 15:53 ` Stephen Hemminger
1 sibling, 2 replies; 32+ messages in thread
From: Bruce Richardson @ 2019-04-03 15:51 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: dev, Declan Doherty, stable
On Wed, Apr 03, 2019 at 08:47:58AM -0700, Stephen Hemminger wrote:
> On Wed, 3 Apr 2019 15:45:01 +0100
> Bruce Richardson <bruce.richardson@intel.com> wrote:
>
> >
> > static void
> > -arp_op_name(uint16_t arp_op, char *buf)
> > +arp_op_name(uint16_t arp_op, char *buf, size_t buf_len)
> > {
> > switch (arp_op) {
> > case ARP_OP_REQUEST:
> > - snprintf(buf, sizeof("ARP Request"), "%s", "ARP Request");
> > + snprintf(buf, buf_len, "%s", "ARP Request");
> > return;
> This should be strlcpy not snprintf
Yes, it should, but I just let that get fixed by cocci script in the later
patch. For this one, I just fixed the most egregious error.
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 1/5] net/bonding: fix buffer length when printing strings
2019-04-03 15:51 ` Bruce Richardson
@ 2019-04-03 15:51 ` Bruce Richardson
2019-04-03 15:53 ` Stephen Hemminger
1 sibling, 0 replies; 32+ messages in thread
From: Bruce Richardson @ 2019-04-03 15:51 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: dev, Declan Doherty, stable
On Wed, Apr 03, 2019 at 08:47:58AM -0700, Stephen Hemminger wrote:
> On Wed, 3 Apr 2019 15:45:01 +0100
> Bruce Richardson <bruce.richardson@intel.com> wrote:
>
> >
> > static void
> > -arp_op_name(uint16_t arp_op, char *buf)
> > +arp_op_name(uint16_t arp_op, char *buf, size_t buf_len)
> > {
> > switch (arp_op) {
> > case ARP_OP_REQUEST:
> > - snprintf(buf, sizeof("ARP Request"), "%s", "ARP Request");
> > + snprintf(buf, buf_len, "%s", "ARP Request");
> > return;
> This should be strlcpy not snprintf
Yes, it should, but I just let that get fixed by cocci script in the later
patch. For this one, I just fixed the most egregious error.
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 4/5] replace snprintf with strlcpy without adding extra include
2019-04-03 14:45 ` [dpdk-dev] [PATCH 4/5] replace snprintf with strlcpy without adding extra include Bruce Richardson
2019-04-03 14:45 ` Bruce Richardson
@ 2019-04-03 15:51 ` Stephen Hemminger
2019-04-03 15:51 ` Stephen Hemminger
2019-04-03 15:56 ` Bruce Richardson
1 sibling, 2 replies; 32+ messages in thread
From: Stephen Hemminger @ 2019-04-03 15:51 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev
On Wed, 3 Apr 2019 15:45:04 +0100
Bruce Richardson <bruce.richardson@intel.com> wrote:
> 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))
I would rather use the name length that is part of the header file.
if (strnlen(name, RTE_RING_NAMESIZE) == RTE_RING_NAMESIZE)
return -ENAMETOOLONG;
strlcpy(r->name, name, sizeof(r->name))
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 4/5] replace snprintf with strlcpy without adding extra include
2019-04-03 15:51 ` Stephen Hemminger
@ 2019-04-03 15:51 ` Stephen Hemminger
2019-04-03 15:56 ` Bruce Richardson
1 sibling, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2019-04-03 15:51 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev
On Wed, 3 Apr 2019 15:45:04 +0100
Bruce Richardson <bruce.richardson@intel.com> wrote:
> 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))
I would rather use the name length that is part of the header file.
if (strnlen(name, RTE_RING_NAMESIZE) == RTE_RING_NAMESIZE)
return -ENAMETOOLONG;
strlcpy(r->name, name, sizeof(r->name))
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 1/5] net/bonding: fix buffer length when printing strings
2019-04-03 15:51 ` Bruce Richardson
2019-04-03 15:51 ` Bruce Richardson
@ 2019-04-03 15:53 ` Stephen Hemminger
2019-04-03 15:53 ` Stephen Hemminger
1 sibling, 1 reply; 32+ messages in thread
From: Stephen Hemminger @ 2019-04-03 15:53 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev, Declan Doherty, stable
On Wed, 3 Apr 2019 16:51:17 +0100
Bruce Richardson <bruce.richardson@intel.com> wrote:
> On Wed, Apr 03, 2019 at 08:47:58AM -0700, Stephen Hemminger wrote:
> > On Wed, 3 Apr 2019 15:45:01 +0100
> > Bruce Richardson <bruce.richardson@intel.com> wrote:
> >
> > >
> > > static void
> > > -arp_op_name(uint16_t arp_op, char *buf)
> > > +arp_op_name(uint16_t arp_op, char *buf, size_t buf_len)
> > > {
> > > switch (arp_op) {
> > > case ARP_OP_REQUEST:
> > > - snprintf(buf, sizeof("ARP Request"), "%s", "ARP Request");
> > > + snprintf(buf, buf_len, "%s", "ARP Request");
> > > return;
> > This should be strlcpy not snprintf
>
> Yes, it should, but I just let that get fixed by cocci script in the later
> patch. For this one, I just fixed the most egregious error.
Ok, I see
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 1/5] net/bonding: fix buffer length when printing strings
2019-04-03 15:53 ` Stephen Hemminger
@ 2019-04-03 15:53 ` Stephen Hemminger
0 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2019-04-03 15:53 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev, Declan Doherty, stable
On Wed, 3 Apr 2019 16:51:17 +0100
Bruce Richardson <bruce.richardson@intel.com> wrote:
> On Wed, Apr 03, 2019 at 08:47:58AM -0700, Stephen Hemminger wrote:
> > On Wed, 3 Apr 2019 15:45:01 +0100
> > Bruce Richardson <bruce.richardson@intel.com> wrote:
> >
> > >
> > > static void
> > > -arp_op_name(uint16_t arp_op, char *buf)
> > > +arp_op_name(uint16_t arp_op, char *buf, size_t buf_len)
> > > {
> > > switch (arp_op) {
> > > case ARP_OP_REQUEST:
> > > - snprintf(buf, sizeof("ARP Request"), "%s", "ARP Request");
> > > + snprintf(buf, buf_len, "%s", "ARP Request");
> > > return;
> > This should be strlcpy not snprintf
>
> Yes, it should, but I just let that get fixed by cocci script in the later
> patch. For this one, I just fixed the most egregious error.
Ok, I see
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 4/5] replace snprintf with strlcpy without adding extra include
2019-04-03 15:51 ` Stephen Hemminger
2019-04-03 15:51 ` Stephen Hemminger
@ 2019-04-03 15:56 ` Bruce Richardson
2019-04-03 15:56 ` Bruce Richardson
2019-04-04 18:05 ` Thomas Monjalon
1 sibling, 2 replies; 32+ messages in thread
From: Bruce Richardson @ 2019-04-03 15:56 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: dev
On Wed, Apr 03, 2019 at 08:51:32AM -0700, Stephen Hemminger wrote:
> On Wed, 3 Apr 2019 15:45:04 +0100
> Bruce Richardson <bruce.richardson@intel.com> wrote:
>
> > 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))
>
> I would rather use the name length that is part of the header file.
>
> if (strnlen(name, RTE_RING_NAMESIZE) == RTE_RING_NAMESIZE)
> return -ENAMETOOLONG;
>
> strlcpy(r->name, name, sizeof(r->name))
>
Yes, though honestly it's a matter of preference. Since this was a scripted
replacement each change wasn't checked in too much detail other than a
cursory check for correctness.
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 4/5] replace snprintf with strlcpy without adding extra include
2019-04-03 15:56 ` Bruce Richardson
@ 2019-04-03 15:56 ` Bruce Richardson
2019-04-04 18:05 ` Thomas Monjalon
1 sibling, 0 replies; 32+ messages in thread
From: Bruce Richardson @ 2019-04-03 15:56 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: dev
On Wed, Apr 03, 2019 at 08:51:32AM -0700, Stephen Hemminger wrote:
> On Wed, 3 Apr 2019 15:45:04 +0100
> Bruce Richardson <bruce.richardson@intel.com> wrote:
>
> > 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))
>
> I would rather use the name length that is part of the header file.
>
> if (strnlen(name, RTE_RING_NAMESIZE) == RTE_RING_NAMESIZE)
> return -ENAMETOOLONG;
>
> strlcpy(r->name, name, sizeof(r->name))
>
Yes, though honestly it's a matter of preference. Since this was a scripted
replacement each change wasn't checked in too much detail other than a
cursory check for correctness.
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 4/5] replace snprintf with strlcpy without adding extra include
2019-04-03 15:56 ` Bruce Richardson
2019-04-03 15:56 ` Bruce Richardson
@ 2019-04-04 18:05 ` Thomas Monjalon
2019-04-04 18:05 ` Thomas Monjalon
1 sibling, 1 reply; 32+ messages in thread
From: Thomas Monjalon @ 2019-04-04 18:05 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev, Stephen Hemminger
03/04/2019 17:56, Bruce Richardson:
> On Wed, Apr 03, 2019 at 08:51:32AM -0700, Stephen Hemminger wrote:
> > On Wed, 3 Apr 2019 15:45:04 +0100
> > Bruce Richardson <bruce.richardson@intel.com> wrote:
> >
> > > 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))
> >
> > I would rather use the name length that is part of the header file.
> >
> > if (strnlen(name, RTE_RING_NAMESIZE) == RTE_RING_NAMESIZE)
> > return -ENAMETOOLONG;
> >
> > strlcpy(r->name, name, sizeof(r->name))
> >
> Yes, though honestly it's a matter of preference. Since this was a scripted
> replacement each change wasn't checked in too much detail other than a
> cursory check for correctness.
I prefer using sizeof/strlen rather than the constant used for allocation.
Reasons are:
- it's easier to understand the intent
- it's easier to change how the allocation size is chosen
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 4/5] replace snprintf with strlcpy without adding extra include
2019-04-04 18:05 ` Thomas Monjalon
@ 2019-04-04 18:05 ` Thomas Monjalon
0 siblings, 0 replies; 32+ messages in thread
From: Thomas Monjalon @ 2019-04-04 18:05 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev, Stephen Hemminger
03/04/2019 17:56, Bruce Richardson:
> On Wed, Apr 03, 2019 at 08:51:32AM -0700, Stephen Hemminger wrote:
> > On Wed, 3 Apr 2019 15:45:04 +0100
> > Bruce Richardson <bruce.richardson@intel.com> wrote:
> >
> > > 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))
> >
> > I would rather use the name length that is part of the header file.
> >
> > if (strnlen(name, RTE_RING_NAMESIZE) == RTE_RING_NAMESIZE)
> > return -ENAMETOOLONG;
> >
> > strlcpy(r->name, name, sizeof(r->name))
> >
> Yes, though honestly it's a matter of preference. Since this was a scripted
> replacement each change wasn't checked in too much detail other than a
> cursory check for correctness.
I prefer using sizeof/strlen rather than the constant used for allocation.
Reasons are:
- it's easier to understand the intent
- it's easier to change how the allocation size is chosen
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying
2019-04-03 14:45 [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying Bruce Richardson
` (6 preceding siblings ...)
2019-04-03 14:57 ` [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying Wiles, Keith
@ 2019-04-04 20:11 ` Thomas Monjalon
2019-04-04 20:11 ` Thomas Monjalon
7 siblings, 1 reply; 32+ messages in thread
From: Thomas Monjalon @ 2019-04-04 20:11 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev
03/04/2019 16:45, Bruce Richardson:
> There are quite a few instances remaining in DPDK where snprintf is being
> used for string copying. These were not being picked up by our existing
> coccinelle script, but that can be fixed by editing the script and running
> it against our code. In the process a bug was found and fixed in the
> bonding pmd, where we were incorrectly specifiying the buffer length
> parameter to snprintf.
>
> The actual replacement was done in two phases - first replacing all
> instances where only the snprintf line in question needed changing, then
> fixing the other instances where we also needed to add in the header
> include. [Using two stages allowed the header addition to be automated too,
> since we had a list of files where every one needed the header inclusion]
>
>
> Bruce Richardson (5):
> net/bonding: fix buffer length when printing strings
> devtools/cocci: make strlcpy replacement smarter
> devtools/cocci: create safer version of strlcpy script
> replace snprintf with strlcpy without adding extra include
> replace snprintf with strlcpy
Applied (with 2 rebase changes), thanks
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying
2019-04-04 20:11 ` Thomas Monjalon
@ 2019-04-04 20:11 ` Thomas Monjalon
0 siblings, 0 replies; 32+ messages in thread
From: Thomas Monjalon @ 2019-04-04 20:11 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev
03/04/2019 16:45, Bruce Richardson:
> There are quite a few instances remaining in DPDK where snprintf is being
> used for string copying. These were not being picked up by our existing
> coccinelle script, but that can be fixed by editing the script and running
> it against our code. In the process a bug was found and fixed in the
> bonding pmd, where we were incorrectly specifiying the buffer length
> parameter to snprintf.
>
> The actual replacement was done in two phases - first replacing all
> instances where only the snprintf line in question needed changing, then
> fixing the other instances where we also needed to add in the header
> include. [Using two stages allowed the header addition to be automated too,
> since we had a list of files where every one needed the header inclusion]
>
>
> Bruce Richardson (5):
> net/bonding: fix buffer length when printing strings
> devtools/cocci: make strlcpy replacement smarter
> devtools/cocci: create safer version of strlcpy script
> replace snprintf with strlcpy without adding extra include
> replace snprintf with strlcpy
Applied (with 2 rebase changes), thanks
^ permalink raw reply [flat|nested] 32+ messages in thread
end of thread, other threads:[~2019-04-04 20:11 UTC | newest]
Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-03 14:45 [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying Bruce Richardson
2019-04-03 14:45 ` Bruce Richardson
2019-04-03 14:45 ` [dpdk-dev] [PATCH 1/5] net/bonding: fix buffer length when printing strings Bruce Richardson
2019-04-03 14:45 ` Bruce Richardson
2019-04-03 15:47 ` Stephen Hemminger
2019-04-03 15:47 ` Stephen Hemminger
2019-04-03 15:51 ` Bruce Richardson
2019-04-03 15:51 ` Bruce Richardson
2019-04-03 15:53 ` Stephen Hemminger
2019-04-03 15:53 ` Stephen Hemminger
2019-04-03 14:45 ` [dpdk-dev] [PATCH 2/5] devtools/cocci: make strlcpy replacement smarter Bruce Richardson
2019-04-03 14:45 ` Bruce Richardson
2019-04-03 14:45 ` [dpdk-dev] [PATCH 3/5] devtools/cocci: create safer version of strlcpy script Bruce Richardson
2019-04-03 14:45 ` Bruce Richardson
2019-04-03 14:45 ` [dpdk-dev] [PATCH 4/5] replace snprintf with strlcpy without adding extra include Bruce Richardson
2019-04-03 14:45 ` Bruce Richardson
2019-04-03 15:51 ` Stephen Hemminger
2019-04-03 15:51 ` Stephen Hemminger
2019-04-03 15:56 ` Bruce Richardson
2019-04-03 15:56 ` Bruce Richardson
2019-04-04 18:05 ` Thomas Monjalon
2019-04-04 18:05 ` Thomas Monjalon
2019-04-03 14:45 ` [dpdk-dev] [PATCH 5/5] replace snprintf with strlcpy Bruce Richardson
2019-04-03 14:45 ` Bruce Richardson
2019-04-03 14:57 ` [dpdk-dev] [PATCH 0/5] clean up snprintf use for string copying Wiles, Keith
2019-04-03 14:57 ` Wiles, Keith
2019-04-03 15:13 ` Bruce Richardson
2019-04-03 15:13 ` Bruce Richardson
2019-04-03 15:27 ` Stephen Hemminger
2019-04-03 15:27 ` Stephen Hemminger
2019-04-04 20:11 ` Thomas Monjalon
2019-04-04 20:11 ` Thomas Monjalon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).