DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jie Hai <haijie1@huawei.com>
To: <dev@dpdk.org>, Ciara Power <ciara.power@intel.com>,
	Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>,
	Pablo de Lara <pablo.de.lara.guarch@intel.com>,
	Piotr Azarewicz <piotr.azarewicz@intel.com>,
	Michal Kobylinski <michalx.kobylinski@intel.com>,
	Declan Doherty <declan.doherty@intel.com>,
	Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>,
	Marcin Kerlin <marcinx.kerlin@intel.com>
Cc: <haijie1@huawei.com>, <lihuisong@huawei.com>, <fengchengwen@huawei.com>
Subject: [PATCH v3 04/22] app/crypto-perf: replace strtok with reentrant version
Date: Tue, 14 Nov 2023 18:59:48 +0800	[thread overview]
Message-ID: <20231114110006.91148-5-haijie1@huawei.com> (raw)
In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com>

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: f6cefe253cc8 ("app/crypto-perf: add range/list of sizes")
Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test application")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test-crypto-perf/cperf_options_parsing.c     | 16 +++++++++-------
 app/test-crypto-perf/cperf_test_vector_parsing.c | 10 ++++++----
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c
index 75afedc7fd6e..77cda0eb8e6f 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -161,6 +161,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 {
 	char *token;
 	uint32_t number;
+	char *sp = NULL;
 
 	char *copy_arg = strdup(arg);
 
@@ -168,7 +169,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 		return -1;
 
 	errno = 0;
-	token = strtok(copy_arg, ":");
+	token = strtok_r(copy_arg, ":", &sp);
 
 	/* Parse minimum value */
 	if (token != NULL) {
@@ -182,7 +183,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 	} else
 		goto err_range;
 
-	token = strtok(NULL, ":");
+	token = strtok_r(NULL, ":", &sp);
 
 	/* Parse increment value */
 	if (token != NULL) {
@@ -196,7 +197,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 	} else
 		goto err_range;
 
-	token = strtok(NULL, ":");
+	token = strtok_r(NULL, ":", &sp);
 
 	/* Parse maximum value */
 	if (token != NULL) {
@@ -211,7 +212,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 	} else
 		goto err_range;
 
-	if (strtok(NULL, ":") != NULL)
+	if (strtok_r(NULL, ":", &sp) != NULL)
 		goto err_range;
 
 	free(copy_arg);
@@ -230,6 +231,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
 	uint8_t count = 0;
 	uint32_t temp_min;
 	uint32_t temp_max;
+	char *sp = NULL;
 
 	char *copy_arg = strdup(arg);
 
@@ -237,7 +239,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
 		return -1;
 
 	errno = 0;
-	token = strtok(copy_arg, ",");
+	token = strtok_r(copy_arg, ",", &sp);
 
 	/* Parse first value */
 	if (token != NULL) {
@@ -253,7 +255,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
 	} else
 		goto err_list;
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 
 	while (token != NULL) {
 		if (count == MAX_LIST) {
@@ -275,7 +277,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
 		if (number > temp_max)
 			temp_max = number;
 
-		token = strtok(NULL, ",");
+		token = strtok_r(NULL, ",", &sp);
 	}
 
 	if (min)
diff --git a/app/test-crypto-perf/cperf_test_vector_parsing.c b/app/test-crypto-perf/cperf_test_vector_parsing.c
index 737d61d4af6b..4d2e6053e745 100644
--- a/app/test-crypto-perf/cperf_test_vector_parsing.c
+++ b/app/test-crypto-perf/cperf_test_vector_parsing.c
@@ -220,8 +220,9 @@ parse_values(char *tokens, uint8_t **data, uint32_t *data_length)
 
 	uint8_t *values, *values_resized;
 	char *tok, *error = NULL;
+	char *sp = NULL;
 
-	tok = strtok(tokens, CPERF_VALUE_DELIMITER);
+	tok = strtok_r(tokens, CPERF_VALUE_DELIMITER, &sp);
 	if (tok == NULL)
 		return -1;
 
@@ -252,7 +253,7 @@ parse_values(char *tokens, uint8_t **data, uint32_t *data_length)
 			return -1;
 		}
 
-		tok = strtok(NULL, CPERF_VALUE_DELIMITER);
+		tok = strtok_r(NULL, CPERF_VALUE_DELIMITER, &sp);
 		if (tok == NULL)
 			break;
 
@@ -283,6 +284,7 @@ parse_entry(char *entry, struct cperf_test_vector *vector,
 
 	uint8_t *data = NULL;
 	char *token, *key_token;
+	char *sp = NULL;
 
 	if (entry == NULL) {
 		printf("Expected entry value\n");
@@ -290,10 +292,10 @@ parse_entry(char *entry, struct cperf_test_vector *vector,
 	}
 
 	/* get key */
-	token = strtok(entry, CPERF_ENTRY_DELIMITER);
+	token = strtok_r(entry, CPERF_ENTRY_DELIMITER, &sp);
 	key_token = token;
 	/* get values for key */
-	token = strtok(NULL, CPERF_ENTRY_DELIMITER);
+	token = strtok_r(NULL, CPERF_ENTRY_DELIMITER, &sp);
 
 	if (key_token == NULL || token == NULL) {
 		printf("Expected 'key = values' but was '%.40s'..\n", entry);
-- 
2.30.0


  parent reply	other threads:[~2023-11-14 11:10 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
2023-11-13 10:45 ` [PATCH 01/21] app/graph: " Jie Hai
2023-11-13 10:45 ` [PATCH 02/21] app/test-bbdev: " Jie Hai
2023-11-13 10:45 ` [PATCH 03/21] app/test-compress-perf: " Jie Hai
2023-11-13 10:45 ` [PATCH 04/21] app/test-crypto-perf: " Jie Hai
2023-11-13 10:45 ` [PATCH 05/21] app/test-dma-perf: " Jie Hai
2023-11-13 10:45 ` [PATCH 06/21] app/test-fib: " Jie Hai
2023-11-13 10:45 ` [PATCH 07/21] app/dpdk-test-flow-perf: " Jie Hai
2023-11-13 10:45 ` [PATCH 08/21] app/test-mldev: " Jie Hai
2023-11-13 10:45 ` [PATCH 09/21] lib/dmadev: " Jie Hai
2023-11-13 10:45 ` [PATCH 10/21] lib/eal: " Jie Hai
2023-11-13 16:27   ` Stephen Hemminger
2023-11-14  1:05     ` fengchengwen
2023-11-14  1:08       ` Stephen Hemminger
2023-11-13 10:45 ` [PATCH 11/21] lib/ethdev: " Jie Hai
2023-11-13 10:45 ` [PATCH 12/21] lib/eventdev: " Jie Hai
2023-11-13 10:45 ` [PATCH 13/21] lib/telemetry: " Jie Hai
2023-11-13 10:45 ` [PATCH 14/21] " Jie Hai
2023-11-13 10:45 ` [PATCH 15/21] bus/fslmc: " Jie Hai
2023-11-15  2:41   ` Sachin Saxena
2023-11-13 10:45 ` [PATCH 16/21] common/cnxk: " Jie Hai
2023-11-13 10:45 ` [PATCH 17/21] event/cnxk: " Jie Hai
2023-11-13 10:45 ` [PATCH 18/21] net/ark: " Jie Hai
2023-11-13 10:45 ` [PATCH 19/21] raw/cnxk_gpio: " Jie Hai
2023-11-13 10:45 ` [PATCH 20/21] examples/l2fwd-crypto: " Jie Hai
2023-11-13 10:45 ` [PATCH 21/21] examples/vhost: " Jie Hai
2023-11-13 16:26   ` Stephen Hemminger
2023-11-13 11:00 ` [PATCH 00/21] " Thomas Monjalon
2023-11-13 11:33 ` fengchengwen
2023-11-13 16:25 ` Stephen Hemminger
2023-11-13 17:09 ` Tyler Retzlaff
2023-11-14 12:50   ` Jie Hai
2023-11-14 17:32     ` Tyler Retzlaff
2023-11-14 17:34       ` Tyler Retzlaff
2023-11-14 17:49         ` Tyler Retzlaff
2023-11-15  3:02           ` fengchengwen
2023-11-15 11:27             ` Morten Brørup
2023-11-15 15:08               ` Stephen Hemminger
2023-11-21  3:32                 ` Jie Hai
2024-02-01 11:13                   ` David Marchand
2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
2023-11-14  8:41   ` [PATCH v2 01/22] app/graph: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 02/22] app/bbdev: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 03/22] app/compress-perf: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 04/22] app/crypto-perf: " Jie Hai
2024-01-11 17:10     ` Power, Ciara
2023-11-14  8:41   ` [PATCH v2 05/22] app/dma-perf: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 06/22] app/test-fib: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 07/22] app/flow-perf: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 08/22] app/test-mldev: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 09/22] dmadev: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 10/22] eal: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 11/22] ethdev: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 12/22] eventdev: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 13/22] security: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 14/22] telemetry: " Jie Hai
2024-01-11 17:13     ` Power, Ciara
2023-11-14  8:41   ` [PATCH v2 15/22] bus/fslmc: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 16/22] common/cnxk: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 17/22] event/cnxk: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 18/22] net/ark: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 19/22] raw/cnxk_gpio: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 20/22] examples/l2fwd-crypto: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 21/22] examples/vhost: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 22/22] devtools: check for some reentrant function Jie Hai
2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
2023-11-14 10:59   ` [PATCH v3 01/22] app/graph: " Jie Hai
2023-11-15  0:07     ` Stephen Hemminger
2023-11-14 10:59   ` [PATCH v3 02/22] app/bbdev: " Jie Hai
2023-11-15  0:09     ` Stephen Hemminger
2023-11-14 10:59   ` [PATCH v3 03/22] app/compress-perf: " Jie Hai
2023-11-14 10:59   ` Jie Hai [this message]
2023-11-14 10:59   ` [PATCH v3 05/22] app/dma-perf: " Jie Hai
2023-11-14 10:59   ` [PATCH v3 06/22] app/test-fib: " Jie Hai
2023-11-14 10:59   ` [PATCH v3 07/22] app/flow-perf: " Jie Hai
2023-11-14 10:59   ` [PATCH v3 08/22] app/test-mldev: " Jie Hai
2023-11-14 10:59   ` [PATCH v3 09/22] dmadev: " Jie Hai
2023-11-14 10:59   ` [PATCH v3 10/22] eal: " Jie Hai
2023-11-15  7:17     ` [EXT] " Amit Prakash Shukla
2023-11-14 10:59   ` [PATCH v3 11/22] ethdev: " Jie Hai
2023-12-16 10:01     ` Andrew Rybchenko
2023-11-14 10:59   ` [PATCH v3 12/22] eventdev: " Jie Hai
2023-11-14 10:59   ` [PATCH v3 13/22] security: " Jie Hai
2023-11-14 10:59   ` [PATCH v3 14/22] telemetry: " Jie Hai
2023-11-14 10:59   ` [PATCH v3 15/22] bus/fslmc: " Jie Hai
2023-11-14 11:00   ` [PATCH v3 16/22] common/cnxk: " Jie Hai
2023-11-14 11:00   ` [PATCH v3 17/22] event/cnxk: " Jie Hai
2023-11-14 11:00   ` [PATCH v3 18/22] net/ark: " Jie Hai
2023-11-14 11:00   ` [PATCH v3 19/22] raw/cnxk_gpio: " Jie Hai
2023-11-14 11:00   ` [PATCH v3 20/22] examples/l2fwd-crypto: " Jie Hai
2023-11-14 11:00   ` [PATCH v3 21/22] examples/vhost: " Jie Hai
2023-11-14 11:00   ` [PATCH v3 22/22] devtools: check for some reentrant function Jie Hai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231114110006.91148-5-haijie1@huawei.com \
    --to=haijie1@huawei.com \
    --cc=ciara.power@intel.com \
    --cc=declan.doherty@intel.com \
    --cc=dev@dpdk.org \
    --cc=fengchengwen@huawei.com \
    --cc=lihuisong@huawei.com \
    --cc=marcinx.kerlin@intel.com \
    --cc=michalx.kobylinski@intel.com \
    --cc=pablo.de.lara.guarch@intel.com \
    --cc=piotr.azarewicz@intel.com \
    --cc=sergio.gonzalez.monroy@intel.com \
    --cc=slawomirx.mrozowicz@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).