[v6,20/25] common/qat: replace strtok with reentrant version

Message ID 20241122110458.2156907-21-haijie1@huawei.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series replace strtok with strtok_r |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jie Hai Nov. 22, 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: 99ab2806687b ("common/qat: isolate parser arguments configuration")

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 drivers/common/qat/qat_device.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Patch

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);