[PATCH 21/21] examples/vhost: replace strtok with strtok_r
Jie Hai
haijie1 at huawei.com
Mon Nov 13 11:45:50 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 function.
Signed-off-by: Jie Hai <haijie1 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