[PATCH v5 23/25] examples/l2fwd-crypto: replace strtok with reentrant version
Jie Hai
haijie1 at huawei.com
Fri Nov 8 12:04:02 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: 1df9c0109f4c ("examples/l2fwd-crypto: parse key parameters")
Signed-off-by: Jie Hai <haijie1 at huawei.com>
---
examples/l2fwd-crypto/main.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index a441312f5524..7128bd2e72cf 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -43,6 +43,7 @@
#include <rte_prefetch.h>
#include <rte_random.h>
#include <rte_hexdump.h>
+#include <rte_os_shim.h>
#ifdef RTE_CRYPTO_SCHEDULER
#include <rte_cryptodev_scheduler.h>
#endif
@@ -1105,12 +1106,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);
--
2.22.0
More information about the dev
mailing list