[PATCH v5 16/25] common/cnxk: replace strtok with reentrant version
Jie Hai
haijie1 at huawei.com
Fri Nov 8 12:03:55 CET 2024
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>
Acked-by: Morten Brørup <mb at smartsharesystems.com>
Acked-by: Stephen Hemminger <stephen at networkplumber.org>
---
drivers/common/cnxk/cnxk_telemetry_nix.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/common/cnxk/cnxk_telemetry_nix.c b/drivers/common/cnxk/cnxk_telemetry_nix.c
index abeefafe1e19..a0b587c97c63 100644
--- a/drivers/common/cnxk/cnxk_telemetry_nix.c
+++ b/drivers/common/cnxk/cnxk_telemetry_nix.c
@@ -3,6 +3,7 @@
*/
#include <ctype.h>
+#include <rte_os_shim.h>
#include "cnxk_telemetry.h"
#include "roc_api.h"
#include "roc_priv.h"
@@ -1015,7 +1016,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;
@@ -1023,11 +1024,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)
@@ -1036,7 +1037,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)
@@ -1052,7 +1053,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)
@@ -1068,7 +1069,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.22.0
More information about the dev
mailing list