Skip to contentSkip to conversation

net/af_xdp: use strlcpy instead of strncpy

PATCH Applied Ciara Loftus 3 participants 5 messages Oct 7, 2020 – Oct 9, 2020 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net/af_xdp: use strlcpy instead of strncpy

strncpy may leave the destination buffer not NULL terminated so use strlcpy instead.

Coverity issue: 362975

Fixes 339b88c6a91f ("net/af_xdp: support multi-queue")

---
v2:
* use strlcpy instead of snprintf

 drivers/net/af_xdp/rte_eth_af_xdp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +1 -1
index eaf2c9c873..ac00cbab8e 100644
@@ -1362,7 +1362,7 @@ xdp_get_channels_info(const char *if_name, int *max_queues,
 
 	channels.cmd = ETHTOOL_GCHANNELS;
 	ifr.ifr_data = (void *)&channels;
-	strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
+	strlcpy(ifr.ifr_name, if_name, IFNAMSIZ);
 	ret = ioctl(fd, SIOCETHTOOL, &ifr);
 	if (ret) {
 		if (errno == EOPNOTSUPP) {
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 1/1 net/af_xdp: use rte_strscpy instead of strncpy

strncpy may leave the destination buffer not NULL terminated so use rte_strscpy instead.

Coverity issue: 362975

Fixes 339b88c6a91f ("net/af_xdp: support multi-queue")

---
v3:
* use rte_strscpy instead of strlcpy

v2:
* use strlcpy instead of snprintf

 drivers/net/af_xdp/rte_eth_af_xdp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +1 -1
index eaf2c9c873..ac00cbab8e 100644
@@ -1362,7 +1362,7 @@ xdp_get_channels_info(const char *if_name, int *max_queues,
 
 	channels.cmd = ETHTOOL_GCHANNELS;
 	ifr.ifr_data = (void *)&channels;
-	strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
+	strlcpy(ifr.ifr_name, if_name, IFNAMSIZ);
 	ret = ioctl(fd, SIOCETHTOOL, &ifr);
 	if (ret) {
 		if (errno == EOPNOTSUPP) {
Signature · 1 line
2.17.1
#2 lore raw

PATCH v4 1/1 net/af_xdp: use rte_strscpy instead of strncpy

strncpy may leave the destination buffer not NULL terminated so use rte_strscpy instead.

Coverity issue: 362975

Fixes 339b88c6a91f ("net/af_xdp: support multi-queue")

---
v4:
* actually use rte_strscpy instead of strlcpy

v3:
* use rte_strscpy instead of strlcpy

v2:
* use strlcpy instead of snprintf

 drivers/net/af_xdp/rte_eth_af_xdp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +1 -1
index eaf2c9c873..f394c57a74 100644
@@ -1362,7 +1362,7 @@ xdp_get_channels_info(const char *if_name, int *max_queues,
 
 	channels.cmd = ETHTOOL_GCHANNELS;
 	ifr.ifr_data = (void *)&channels;
-	strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
+	rte_strscpy(ifr.ifr_name, if_name, IFNAMSIZ);
 	ret = ioctl(fd, SIOCETHTOOL, &ifr);
 	if (ret) {
 		if (errno == EOPNOTSUPP) {
Signature · 1 line
2.17.1
Acked-by on v2 1/1
#3 lore raw
In reply to Ciara Loftus
Quoted 7 lines · Ciara Loftus

strncpy may leave the destination buffer not NULL terminated so use strlcpy instead.

Coverity issue: 362975

Fixes 339b88c6a91f ("net/af_xdp: support multi-queue")

---

If the community prefers using rte_strscpy, this ack can also apply to v4 too. :-)

Quoted 22 lines

v2:
* use strlcpy instead of snprintf

 drivers/net/af_xdp/rte_eth_af_xdp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +1 -1
index eaf2c9c873..ac00cbab8e 100644
@@ -1362,7 +1362,7 @@ xdp_get_channels_info(const char *if_name, int *max_queues,
 
 	channels.cmd = ETHTOOL_GCHANNELS;
 	ifr.ifr_data = (void *)&channels;
-	strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
+	strlcpy(ifr.ifr_name, if_name, IFNAMSIZ);
 	ret = ioctl(fd, SIOCETHTOOL, &ifr);
 	if (ret) {
 		if (errno == EOPNOTSUPP) {
Signature · 1 line
2.17.1