[PATCH v2 06/22] app/test-fib: replace strtok with reentrant version

Jie Hai haijie1 at huawei.com
Tue Nov 14 09:41:17 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: 103809d032cd ("app/test-fib: add test application for FIB")
Cc: stable at dpdk.org

Signed-off-by: Jie Hai <haijie1 at huawei.com>
Acked-by: Chengwen Feng <fengchengwen at huawei.com>
---
 app/test-fib/main.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/app/test-fib/main.c b/app/test-fib/main.c
index 75a56135f212..95f6bd467b49 100644
--- a/app/test-fib/main.c
+++ b/app/test-fib/main.c
@@ -223,9 +223,9 @@ parse_distrib(uint8_t depth_lim, const uint32_t n)
 	uint32_t nrpd[128 + 1] = {0}; /* number of routes per depth */
 	uint32_t n_routes;
 	uint8_t depth, ratio, ratio_acc = 0;
-	char *in;
+	char *in, *sp = NULL;
 
-	in = strtok(distrib_string, ",");
+	in = strtok_s(distrib_string, ",", &sp);
 
 	/*parse configures routes percentage ratios*/
 	while (in != NULL) {
@@ -265,7 +265,7 @@ parse_distrib(uint8_t depth_lim, const uint32_t n)
 		}
 
 		/*number of configured depths in*/
-		in = strtok(NULL, ",");
+		in = strtok_s(NULL, ",", &sp);
 	}
 
 	if (ratio_acc > 100) {
@@ -542,10 +542,10 @@ parse_lookup(FILE *f, int af)
 	int ret, i = 0;
 	uint8_t *tbl = (uint8_t *)config.lookup_tbl;
 	int step = (af == AF_INET) ? 4 : 16;
-	char *s;
+	char *s, *sp = NULL;
 
 	while (fgets(line, sizeof(line), f) != NULL) {
-		s = strtok(line, " \t\n");
+		s = strtok_s(line, " \t\n", &sp);
 		if (s == NULL)
 			return -EINVAL;
 		ret = inet_pton(af, s, &tbl[i]);
-- 
2.30.0



More information about the dev mailing list