[21/21] examples/vhost: replace strtok with strtok_r
Checks
Commit Message
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
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.
@@ -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;