[PATCH v3 21/22] examples/vhost: replace strtok with reentrant version

Jie Hai haijie1 at huawei.com
Tue Nov 14 12:00:05 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: 3a04ecb21420 ("examples/vhost: add async vhost args parsing")
Cc: stable at dpdk.org

Signed-off-by: Jie Hai <haijie1 at huawei.com>
Acked-by: Chengwen Feng <fengchengwen at huawei.com>
---
 examples/vhost/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index ce5c1efddf5c..e8b3a97c48a4 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -246,6 +246,7 @@ open_dma(const char *value)
 	char *ptrs[2];
 	char *start, *end, *substr;
 	int64_t socketid, vring_id;
+	char *sp = NULL;
 
 	struct rte_dma_info info;
 	struct rte_dma_conf dev_config = { .nb_vchans = 1 };
@@ -269,7 +270,7 @@ open_dma(const char *value)
 
 	/* process DMA devices within bracket. */
 	addrs++;
-	substr = strtok(addrs, ";]");
+	substr = strtok_r(addrs, ";]", &sp);
 	if (!substr) {
 		ret = -1;
 		goto out;
-- 
2.30.0



More information about the dev mailing list