[PATCH v3 16/22] common/cnxk: replace strtok with reentrant version
Jie Hai
haijie1 at huawei.com
Tue Nov 14 12:00:00 CET 2023
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: af75aac78978 ("common/cnxk: support telemetry for NIX")
Cc: stable at dpdk.org
Signed-off-by: Jie Hai <haijie1 at huawei.com>
Acked-by: Chengwen Feng <fengchengwen at huawei.com>
---
drivers/common/cnxk/cnxk_telemetry_nix.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/common/cnxk/cnxk_telemetry_nix.c b/drivers/common/cnxk/cnxk_telemetry_nix.c
index ccae5d7853af..8054c3cf910c 100644
--- a/drivers/common/cnxk/cnxk_telemetry_nix.c
+++ b/drivers/common/cnxk/cnxk_telemetry_nix.c
@@ -761,7 +761,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
struct plt_tel_data *d)
{
struct nix_tel_node *node;
- char *name, *param;
+ char *name, *param, *sp = NULL;
char buf[1024];
int rc = -1;
@@ -769,11 +769,11 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
goto exit;
plt_strlcpy(buf, params, PCI_PRI_STR_SIZE + 1);
- name = strtok(buf, ",");
+ name = strtok_r(buf, ",", &sp);
if (name == NULL)
goto exit;
- param = strtok(NULL, "\0");
+ param = strtok_r(NULL, "\0", &sp);
node = nix_tel_node_get_by_pcidev_name(name);
if (!node)
@@ -782,7 +782,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
plt_tel_data_start_dict(d);
if (strstr(cmd, "rq")) {
- char *tok = strtok(param, ",");
+ char *tok = strtok_r(param, ",", &sp);
int rq;
if (!tok)
@@ -798,7 +798,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
rc = cnxk_tel_nix_rq(node->rqs[rq], d);
} else if (strstr(cmd, "cq")) {
- char *tok = strtok(param, ",");
+ char *tok = strtok_r(param, ",", &sp);
int cq;
if (!tok)
@@ -814,7 +814,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
rc = cnxk_tel_nix_cq(node->cqs[cq], d);
} else if (strstr(cmd, "sq")) {
- char *tok = strtok(param, ",");
+ char *tok = strtok_r(param, ",", &sp);
int sq;
if (!tok)
--
2.30.0
More information about the dev
mailing list