Skip to contentSkip to conversation

eal/linux: use strlcpy in uevent parsing

PATCH Superseded Thomas Monjalon 2 participants 4 messages Apr 17, 2018 – Apr 23, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eal/linux: use strlcpy in uevent parsing

Support of strlcpy has recently been added to DPDK.

This replacement has been generated by the coccinelle script:
devtools/cocci.sh devtools/cocci/strlcpy.cocci

Fixes 0d0f478d0483 ("eal/linux: add uevent parse and process")
---
 lib/librte_eal/linuxapp/eal/eal_dev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/librte_eal/linuxapp/eal/eal_dev.c +3 -3
index 9478a39a5..d02bba11e 100644
@@ -94,15 +94,15 @@ dev_uev_parse(const char *buf, struct rte_dev_event *event, int length)
 		if (!strncmp(buf, "ACTION=", 7)) {
 			buf += 7;
 			i += 7;
-			snprintf(action, sizeof(action), "%s", buf);
+			strlcpy(action, buf, sizeof(action));
 		} else if (!strncmp(buf, "SUBSYSTEM=", 10)) {
 			buf += 10;
 			i += 10;
-			snprintf(subsystem, sizeof(subsystem), "%s", buf);
+			strlcpy(subsystem, buf, sizeof(subsystem));
 		} else if (!strncmp(buf, "PCI_SLOT_NAME=", 14)) {
 			buf += 14;
 			i += 14;
-			snprintf(pci_slot_name, sizeof(subsystem), "%s", buf);
+			strlcpy(pci_slot_name, buf, sizeof(subsystem));
 			event->devname = strdup(pci_slot_name);
 		}
 		for (; i < length; i++) {
Signature · 1 line
2.16.2
#1 lore raw

PATCH v2 1/1 eal/linux: use strlcpy in uevent parsing

Support of strlcpy has recently been added to DPDK.

This replacement has been generated by the coccinelle script:
devtools/cocci.sh devtools/cocci/strlcpy.cocci

Fixes 0d0f478d0483 ("eal/linux: add uevent parse and process")

---
v2: add missing include

---
 lib/librte_eal/linuxapp/eal/eal_dev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
lib/librte_eal/linuxapp/eal/eal_dev.c +4 -3
index 9478a39a5..1cf6aebff 100644
@@ -7,6 +7,7 @@
 #include <sys/socket.h>
 #include <linux/netlink.h>
 
+#include <rte_string_fns.h>
 #include <rte_log.h>
 #include <rte_compat.h>
 #include <rte_dev.h>
@@ -94,15 +95,15 @@ dev_uev_parse(const char *buf, struct rte_dev_event *event, int length)
 		if (!strncmp(buf, "ACTION=", 7)) {
 			buf += 7;
 			i += 7;
-			snprintf(action, sizeof(action), "%s", buf);
+			strlcpy(action, buf, sizeof(action));
 		} else if (!strncmp(buf, "SUBSYSTEM=", 10)) {
 			buf += 10;
 			i += 10;
-			snprintf(subsystem, sizeof(subsystem), "%s", buf);
+			strlcpy(subsystem, buf, sizeof(subsystem));
 		} else if (!strncmp(buf, "PCI_SLOT_NAME=", 14)) {
 			buf += 14;
 			i += 14;
-			snprintf(pci_slot_name, sizeof(subsystem), "%s", buf);
+			strlcpy(pci_slot_name, buf, sizeof(subsystem));
 			event->devname = strdup(pci_slot_name);
 		}
 		for (; i < length; i++) {
Signature · 1 line
2.16.2
author Applied
#3 lore raw

23/04/2018 16:15, Bruce Richardson:

Quoted 6 lines · Thomas Monjalon
Quoted 5 lines

Support of strlcpy has recently been added to DPDK.

This replacement has been generated by the coccinelle script:
devtools/cocci.sh devtools/cocci/strlcpy.cocci

Quoted 7 lines
Quoted 4 lines
Fixes 0d0f478d0483 ("eal/linux: add uevent parse and process")

---

LGTM

Applied