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

Message ID 20241108110404.18317-25-haijie1@huawei.com (mailing list archive)
State Changes Requested, archived
Delegated to: David Marchand
Headers
Series [v5,01/25] app/graph: replace strtok with reentrant version |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jie Hai Nov. 8, 2024, 11:04 a.m. UTC
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@huawei.com>
---
 examples/vhost/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Patch

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;