[PATCH v5 21/25] common/qat: replace strtok with reentrant version
Jie Hai
haijie1 at huawei.com
Fri Nov 8 12:04:00 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: 99ab2806687b ("common/qat: isolate parser arguments configuration")
Signed-off-by: Jie Hai <haijie1 at huawei.com>
---
drivers/common/qat/qat_device.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/common/qat/qat_device.c b/drivers/common/qat/qat_device.c
index bca88fd9bded..99153775d883 100644
--- a/drivers/common/qat/qat_device.c
+++ b/drivers/common/qat/qat_device.c
@@ -4,6 +4,7 @@
#include <rte_string_fns.h>
#include <rte_devargs.h>
+#include <rte_os_shim.h>
#include <ctype.h>
#include "qat_device.h"
@@ -222,6 +223,7 @@ qat_dev_parse_command_line(struct qat_pci_device *qat_dev,
{
int len = 0;
char *token = NULL;
+ char *sp = NULL;
if (!devargs)
return 0;
@@ -236,14 +238,14 @@ qat_dev_parse_command_line(struct qat_pci_device *qat_dev,
return -1;
}
strcpy(qat_dev->command_line, devargs->drv_str);
- token = strtok(qat_dev->command_line, ",");
+ token = strtok_r(qat_dev->command_line, ",", &sp);
while (token != NULL) {
if (!cmdline_validate(token)) {
QAT_LOG(ERR, "Incorrect command line argument: %s",
token);
return -1;
}
- token = strtok(NULL, ",");
+ token = strtok_r(NULL, ",", &sp);
}
/* Copy once againe the entire string, strtok already altered the contents */
strcpy(qat_dev->command_line, devargs->drv_str);
--
2.22.0
More information about the dev
mailing list