[v2,14/22] telemetry: replace strtok with reentrant version

Message ID 20231114084133.3573959-15-haijie1@huawei.com (mailing list archive)
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers
Series replace strtok with reentrant version |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jie Hai Nov. 14, 2023, 8:41 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>
---
 lib/telemetry/telemetry.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Comments

Power, Ciara Jan. 11, 2024, 5:13 p.m. UTC | #1
> -----Original Message-----
> From: Jie Hai <haijie1@huawei.com>
> Sent: Tuesday, November 14, 2023 8:41 AM
> To: dev@dpdk.org; Power, Ciara <ciara.power@intel.com>; Wiles, Keith
> <keith.wiles@intel.com>; Richardson, Bruce <bruce.richardson@intel.com>
> Cc: haijie1@huawei.com; lihuisong@huawei.com;
> fengchengwen@huawei.com
> Subject: [PATCH v2 14/22] telemetry: replace strtok with reentrant version
> 
> 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>
  

Patch

diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c
index 92982842a860..ef5cc87c34d1 100644
--- a/lib/telemetry/telemetry.c
+++ b/lib/telemetry/telemetry.c
@@ -371,6 +371,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),
@@ -385,8 +386,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_s(buffer, ",", &sp);
+		const char *param = strtok_s(NULL, "\0", &sp);
 		telemetry_cb fn = unknown_command;
 		int i;