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 9C1CC43325; Tue, 14 Nov 2023 09:47:23 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 36FC840648; Tue, 14 Nov 2023 09:47:16 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 5D6B6402D6 for ; Tue, 14 Nov 2023 09:47:12 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV0K52gHPzWgy6; Tue, 14 Nov 2023 16:46:49 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Tue, 14 Nov 2023 16:47:10 +0800 From: Jie Hai To: , Nicolas Chautru , Maxime Coquelin , Amr Mokhtar CC: , , Subject: [PATCH v2 02/22] app/bbdev: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:13 +0800 Message-ID: <20231114084133.3573959-3-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected 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: 0acdb9866756 ("test/bbdev: add FFT operations cases") Fixes: f714a18885a6 ("app/testbbdev: add test application for bbdev") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- app/test-bbdev/test_bbdev_vector.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/app/test-bbdev/test_bbdev_vector.c b/app/test-bbdev/test_bbdev_vector.c index c26727cd35c4..00a0f99801b7 100644 --- a/app/test-bbdev/test_bbdev_vector.c +++ b/app/test-bbdev/test_bbdev_vector.c @@ -63,8 +63,9 @@ parse_values(char *tokens, uint32_t **data, uint32_t *data_length) uint32_t *values, *values_resized; char *tok, *error = NULL; + char *sp = NULL; - tok = strtok(tokens, VALUE_DELIMITER); + tok = strtok_s(tokens, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; @@ -98,7 +99,7 @@ parse_values(char *tokens, uint32_t **data, uint32_t *data_length) *data_length = *data_length + (strlen(tok) - strlen("0x"))/2; - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_s(NULL, VALUE_DELIMITER, &sp); if (tok == NULL) break; @@ -299,8 +300,9 @@ parse_turbo_flags(char *tokens, uint32_t *op_flags, { char *tok = NULL; uint32_t op_flag_value = 0; + char *sp = NULL; - tok = strtok(tokens, VALUE_DELIMITER); + tok = strtok_s(tokens, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; @@ -330,7 +332,7 @@ parse_turbo_flags(char *tokens, uint32_t *op_flags, *op_flags = *op_flags | op_flag_value; - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_s(NULL, VALUE_DELIMITER, &sp); if (tok == NULL) break; } @@ -368,9 +370,10 @@ static int parse_expected_status(char *tokens, int *status, enum rte_bbdev_op_type op_type) { char *tok = NULL; + char *sp = NULL; bool status_ok = false; - tok = strtok(tokens, VALUE_DELIMITER); + tok = strtok_s(tokens, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; @@ -401,7 +404,7 @@ parse_expected_status(char *tokens, int *status, enum rte_bbdev_op_type op_type) return -1; } - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_s(NULL, VALUE_DELIMITER, &sp); if (tok == NULL) break; } @@ -894,6 +897,7 @@ parse_fft_params(const char *key_token, char *token, int ret = 0, status = 0, i, shift; uint32_t op_flags = 0; char *tok, *err = NULL; + char *sp = NULL; struct rte_bbdev_op_fft *fft = &vector->fft; @@ -922,7 +926,7 @@ parse_fft_params(const char *key_token, char *token, fft->output_leading_depadding = (uint32_t) strtoul(token, &err, 0); ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; } else if (!strcmp(key_token, "window_index")) { - tok = strtok(token, VALUE_DELIMITER); + tok = strtok_s(token, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; for (i = 0; i < FFT_WIN_SIZE; i++) { @@ -930,7 +934,7 @@ parse_fft_params(const char *key_token, char *token, fft->window_index[i / 2] |= (uint32_t) strtoul(tok, &err, 0) << shift; if (i < (FFT_WIN_SIZE - 1)) { - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_s(NULL, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; } @@ -995,6 +999,7 @@ static int parse_entry(char *entry, struct test_bbdev_vector *vector) { int ret = 0; + char *sp = NULL; char *token, *key_token; enum rte_bbdev_op_type op_type = RTE_BBDEV_OP_NONE; @@ -1004,10 +1009,10 @@ parse_entry(char *entry, struct test_bbdev_vector *vector) } /* get key */ - token = strtok(entry, ENTRY_DELIMITER); + token = strtok_s(entry, ENTRY_DELIMITER, &sp); key_token = token; /* get values for key */ - token = strtok(NULL, ENTRY_DELIMITER); + token = strtok_s(NULL, ENTRY_DELIMITER, &sp); if (key_token == NULL || token == NULL) { printf("Expected 'key = values' but was '%.40s'..\n", entry); -- 2.30.0