[v5,20/25] net/cnxk: replace strtok with reentrant version

Message ID 20241108110404.18317-21-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: c8f91985331c ("raw/cnxk_gpio: replace strtok with reentrant version")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Patch

diff --git a/drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c b/drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c
index 86c2453c0983..0b766be11a17 100644
--- a/drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c
+++ b/drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c
@@ -5,6 +5,7 @@ 
 #include <ctype.h>
 
 #include <rte_telemetry.h>
+#include <rte_os_shim.h>
 
 #include <roc_api.h>
 
@@ -214,6 +215,7 @@  parse_params(const char *params, uint32_t *vals, size_t n_vals)
 	char dlim[2] = ",";
 	char *params_args;
 	size_t count = 0;
+	char *sp = NULL;
 	char *token;
 
 	if (vals == NULL || params == NULL || strlen(params) == 0)
@@ -226,10 +228,10 @@  parse_params(const char *params, uint32_t *vals, size_t n_vals)
 	if (params_args == NULL)
 		return -1;
 
-	token = strtok(params_args, dlim);
+	token = strtok_r(params_args, dlim, &sp);
 	while (token && isdigit(*token) && count < n_vals) {
 		vals[count++] = strtoul(token, NULL, 10);
-		token = strtok(NULL, dlim);
+		token = strtok_r(NULL, dlim, &sp);
 	}
 
 	free(params_args);