[v3,20/22] examples/l2fwd-crypto: replace strtok with reentrant version

Message ID 20231114110006.91148-21-haijie1@huawei.com (mailing list archive)
State Changes Requested, archived
Delegated to: David Marchand
Headers
Series replace strtok with reentrant version |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jie Hai Nov. 14, 2023, 11 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: ff5d5b01f8f2 ("examples/l2fwd-crypto: support AES-CCM")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 examples/l2fwd-crypto/main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Patch

diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index efe7eea2a768..06e296776b95 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -1105,12 +1105,12 @@  static int
 parse_bytes(uint8_t *data, char *input_arg, uint16_t max_size)
 {
 	unsigned byte_count;
-	char *token;
+	char *token, *sp = NULL;
 
 	errno = 0;
-	for (byte_count = 0, token = strtok(input_arg, ":");
+	for (byte_count = 0, token = strtok_r(input_arg, ":", &sp);
 			(byte_count < max_size) && (token != NULL);
-			token = strtok(NULL, ":")) {
+			token = strtok_r(NULL, ":", &sp)) {
 
 		int number = (int)strtol(token, NULL, 16);