[PATCH v4 12/13] net/cnxk: replace strtok with reentrant version

Jie Hai haijie1 at huawei.com
Sat Oct 26 12:14:50 CEST 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: c8f91985331c ("raw/cnxk_gpio: replace strtok with reentrant version")
Cc: stable at dpdk.org

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

diff --git a/drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c b/drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c
index 86c2453c0983..fa1d7c063536 100644
--- a/drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c
+++ b/drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c
@@ -214,6 +214,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 +227,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);
-- 
2.22.0



More information about the dev mailing list