[v5,22/25] net/mlx5: replace strtok with reentrant version

Message ID 20241108110404.18317-23-haijie1@huawei.com (mailing list archive)
State Changes Requested, archived
Delegated to: David Marchand
Headers
Series [v5,01/25] app/graph: replace strtok with reentrant version |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jie Hai Nov. 8, 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: 0683c002f7f5 ("net/mlx5: add testpmd commands for GENEVE TLV parser")

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 drivers/net/mlx5/mlx5_testpmd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Patch

diff --git a/drivers/net/mlx5/mlx5_testpmd.c b/drivers/net/mlx5/mlx5_testpmd.c
index 1bb5a89559fe..7bd220fafa46 100644
--- a/drivers/net/mlx5/mlx5_testpmd.c
+++ b/drivers/net/mlx5/mlx5_testpmd.c
@@ -353,6 +353,7 @@  mlx5_test_parse_geneve_option_data(const char *buff, uint8_t data_len,
 				   rte_be32_t **match_data_mask)
 {
 	rte_be32_t *data;
+	char *sp = NULL;
 	char *buff2;
 	char *token;
 	uint8_t i = 0;
@@ -377,7 +378,7 @@  mlx5_test_parse_geneve_option_data(const char *buff, uint8_t data_len,
 		return -ENOMEM;
 	}
 
-	token = strtok(buff2, SPACE_DELIMITER);
+	token = strtok_r(buff2, SPACE_DELIMITER, &sp);
 	while (token != NULL) {
 		if (i == data_len) {
 			TESTPMD_LOG(ERR,
@@ -393,7 +394,7 @@  mlx5_test_parse_geneve_option_data(const char *buff, uint8_t data_len,
 		else
 			data[i] = 0x0;
 
-		token = strtok(NULL, SPACE_DELIMITER);
+		token = strtok_r(NULL, SPACE_DELIMITER, &sp);
 		i++;
 	}