[21/21] examples/vhost: replace strtok with strtok_r

Message ID 20231113104550.2138654-22-haijie1@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series replace strtok with strtok_r |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/github-robot: build success github build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-compile-amd64-testing fail Testing issues
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing fail Testing issues
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS

Commit Message

Jie Hai Nov. 13, 2023, 10:45 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 function.

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

Comments

Stephen Hemminger Nov. 13, 2023, 4:26 p.m. UTC | #1
On Mon, 13 Nov 2023 18:45:50 +0800
Jie Hai <haijie1@huawei.com> wrote:

> 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@huawei.com>

This is in initialization code, can not be called by multiple threads.
  

Patch

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;