From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id ACA9A45CA6; Fri, 8 Nov 2024 12:16:05 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3115043360; Fri, 8 Nov 2024 12:15:46 +0100 (CET) Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by mails.dpdk.org (Postfix) with ESMTP id 791074334C for ; Fri, 8 Nov 2024 12:15:42 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4XlGZv324Pz1ypKZ; Fri, 8 Nov 2024 19:15:51 +0800 (CST) Received: from kwepemf500004.china.huawei.com (unknown [7.202.181.242]) by mail.maildlp.com (Postfix) with ESMTPS id DC9161402CE; Fri, 8 Nov 2024 19:15:40 +0800 (CST) Received: from localhost.localdomain (10.28.79.22) by kwepemf500004.china.huawei.com (7.202.181.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 8 Nov 2024 19:15:40 +0800 From: Jie Hai To: , , , Brian Dooley , Pablo de Lara , Sergio Gonzalez Monroy , Declan Doherty , Piotr Azarewicz , Michal Kobylinski , Marcin Kerlin , Slawomir Mrozowicz CC: , , , Subject: [PATCH v5 04/25] app/crypto-perf: replace strtok with reentrant version Date: Fri, 8 Nov 2024 19:03:43 +0800 Message-ID: <20241108110404.18317-5-haijie1@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20241108110404.18317-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20241108110404.18317-1-haijie1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.28.79.22] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemf500004.china.huawei.com (7.202.181.242) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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") Signed-off-by: Jie Hai Acked-by: Chengwen Feng Acked-by: Ciara Power --- app/test-crypto-perf/cperf_options_parsing.c | 17 ++++++++++------- .../cperf_test_vector_parsing.c | 11 +++++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c index 8abee2d68826..07130e2c27f7 100644 --- a/app/test-crypto-perf/cperf_options_parsing.c +++ b/app/test-crypto-perf/cperf_options_parsing.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "cperf_options.h" #include "cperf_test_common.h" @@ -166,6 +167,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); @@ -173,7 +175,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) { @@ -187,7 +189,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) { @@ -201,7 +203,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) { @@ -216,7 +218,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); @@ -235,6 +237,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); @@ -242,7 +245,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) { @@ -258,7 +261,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) { @@ -280,7 +283,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..b1cc1ef3c91d 100644 --- a/app/test-crypto-perf/cperf_test_vector_parsing.c +++ b/app/test-crypto-perf/cperf_test_vector_parsing.c @@ -9,6 +9,7 @@ #include #include +#include #include "cperf_options.h" #include "cperf_test_vectors.h" @@ -220,8 +221,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 +254,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 +285,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 +293,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.22.0