[v5,14/25] telemetry: replace strtok with reentrant version

Message ID 20241108110404.18317-15-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:03 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: 6dd571fd07c3 ("telemetry: introduce new functionality")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Ciara Power <ciara.power@intel.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/telemetry/telemetry.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Patch

diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c
index 31a2c91c0657..cd1eddc5609c 100644
--- a/lib/telemetry/telemetry.c
+++ b/lib/telemetry/telemetry.c
@@ -19,6 +19,7 @@ 
 #include <rte_common.h>
 #include <rte_spinlock.h>
 #include <rte_log.h>
+#include <rte_os_shim.h>
 
 #include "rte_telemetry.h"
 #include "telemetry_json.h"
@@ -398,6 +399,7 @@  static void *
 client_handler(void *sock_id)
 {
 	int s = (int)(uintptr_t)sock_id;
+	char *sp = NULL;
 	char buffer[1024];
 	char info_str[1024];
 	snprintf(info_str, sizeof(info_str),
@@ -412,8 +414,8 @@  client_handler(void *sock_id)
 	int bytes = read(s, buffer, sizeof(buffer) - 1);
 	while (bytes > 0) {
 		buffer[bytes] = 0;
-		const char *cmd = strtok(buffer, ",");
-		const char *param = strtok(NULL, "\0");
+		const char *cmd = strtok_r(buffer, ",", &sp);
+		const char *param = strtok_r(NULL, "\0", &sp);
 		struct cmd_callback cb = {.fn = unknown_command};
 		int i;