[v5,18/25] net/ark: replace strtok with reentrant version

Message ID 20241108110404.18317-19-haijie1@huawei.com (mailing list archive)
State Changes Requested, archived
Delegated to: David Marchand
Headers
Series [v5,01/25] app/graph: replace strtok with reentrant version |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jie Hai Nov. 8, 2024, 11:03 a.m. UTC
Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 9c7188a68d7b ("net/ark: provide API for hardware modules pktchkr and pktgen")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
---
 drivers/net/ark/ark_pktchkr.c | 11 ++++++-----
 drivers/net/ark/ark_pktgen.c  | 11 ++++++-----
 2 files changed, 12 insertions(+), 10 deletions(-)
  

Patch

diff --git a/drivers/net/ark/ark_pktchkr.c b/drivers/net/ark/ark_pktchkr.c
index e1f336c73c2a..2bb3dd7b5f36 100644
--- a/drivers/net/ark/ark_pktchkr.c
+++ b/drivers/net/ark/ark_pktchkr.c
@@ -7,6 +7,7 @@ 
 
 #include <rte_string_fns.h>
 #include <rte_malloc.h>
+#include <rte_os_shim.h>
 
 #include "ark_pktchkr.h"
 #include "ark_logs.h"
@@ -359,14 +360,14 @@  set_arg(char *arg, char *val)
 void
 ark_pktchkr_parse(char *args)
 {
-	char *argv, *v;
+	char *argv, *v, *sp = NULL;
 	const char toks[] = "=\n\t\v\f \r";
-	argv = strtok(args, toks);
-	v = strtok(NULL, toks);
+	argv = strtok_r(args, toks, &sp);
+	v = strtok_r(NULL, toks, &sp);
 	while (argv && v) {
 		set_arg(argv, v);
-		argv = strtok(NULL, toks);
-		v = strtok(NULL, toks);
+		argv = strtok_r(NULL, toks, &sp);
+		v = strtok_r(NULL, toks, &sp);
 	}
 }
 
diff --git a/drivers/net/ark/ark_pktgen.c b/drivers/net/ark/ark_pktgen.c
index 69ff7072b2ab..4765b8f0992a 100644
--- a/drivers/net/ark/ark_pktgen.c
+++ b/drivers/net/ark/ark_pktgen.c
@@ -8,6 +8,7 @@ 
 #include <rte_string_fns.h>
 #include <rte_malloc.h>
 #include <rte_thread.h>
+#include <rte_os_shim.h>
 
 #include "ark_pktgen.h"
 #include "ark_logs.h"
@@ -340,14 +341,14 @@  pmd_set_arg(char *arg, char *val)
 void
 ark_pktgen_parse(char *args)
 {
-	char *argv, *v;
+	char *argv, *v, *sp = NULL;
 	const char toks[] = " =\n\t\v\f \r";
-	argv = strtok(args, toks);
-	v = strtok(NULL, toks);
+	argv = strtok_r(args, toks, &sp);
+	v = strtok_r(NULL, toks, &sp);
 	while (argv && v) {
 		pmd_set_arg(argv, v);
-		argv = strtok(NULL, toks);
-		v = strtok(NULL, toks);
+		argv = strtok_r(NULL, toks, &sp);
+		v = strtok_r(NULL, toks, &sp);
 	}
 }