[PATCH v3 19/22] raw/cnxk_gpio: replace strtok with reentrant version
Jie Hai
haijie1 at huawei.com
Tue Nov 14 12:00:03 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: ecc0dd455e9a ("raw/cnxk_gpio: add option to select subset of GPIOs")
Cc: stable at dpdk.org
Signed-off-by: Jie Hai <haijie1 at huawei.com>
Acked-by: Chengwen Feng <fengchengwen at huawei.com>
---
drivers/raw/cnxk_gpio/cnxk_gpio.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio.c b/drivers/raw/cnxk_gpio/cnxk_gpio.c
index 29c250672646..a499a258f315 100644
--- a/drivers/raw/cnxk_gpio/cnxk_gpio.c
+++ b/drivers/raw/cnxk_gpio/cnxk_gpio.c
@@ -190,7 +190,7 @@ static int
cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
{
int i, ret, val, queue = 0;
- char *token;
+ char *token, *sp = NULL;
int *list;
list = rte_calloc(NULL, gpiochip->num_gpios, sizeof(*list), 0);
@@ -208,7 +208,7 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
allowlist[strlen(allowlist) - 1] = ' ';
/* quiesce -Wcast-qual */
- token = strtok((char *)(uintptr_t)allowlist, ",");
+ token = strtok_r((char *)(uintptr_t)allowlist, ",", &sp);
do {
errno = 0;
val = strtol(token, NULL, 10);
@@ -234,7 +234,7 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
}
if (i == queue)
list[queue++] = val;
- } while ((token = strtok(NULL, ",")));
+ } while ((token = strtok_r(NULL, ",", &sp)));
free(allowlist);
gpiochip->allowlist = list;
--
2.30.0
More information about the dev
mailing list