[PATCH v5 24/25] examples/vhost: replace strtok with reentrant version

Jie Hai haijie1 at huawei.com
Fri Nov 8 12:04:03 CET 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: 53d3f4778c1d ("vhost: integrate dmadev in asynchronous data-path")

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

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 4391d88c3d15..0fbb11b1d4f4 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -29,6 +29,7 @@
 #include <rte_dmadev.h>
 #include <rte_vhost_async.h>
 #include <rte_thread.h>
+#include <rte_os_shim.h>
 
 #include "main.h"
 
@@ -259,6 +260,7 @@ open_dma(const char *value)
 	uint16_t i = 0;
 	char *dma_arg[RTE_MAX_VHOST_DEVICE];
 	int args_nr;
+	char *sp = NULL;
 
 	if (input == NULL)
 		return -1;
@@ -272,7 +274,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.22.0



More information about the dev mailing list