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(-)
@@ -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);
}
}
@@ -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);
}
}