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: sta...@dpdk.org

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

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);
        }
 }
 
-- 
2.33.0

Reply via email to