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 54E6645CA6; Fri, 8 Nov 2024 12:15:52 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A463D43359; Fri, 8 Nov 2024 12:15:43 +0100 (CET) Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by mails.dpdk.org (Postfix) with ESMTP id DDBEA402DF for ; Fri, 8 Nov 2024 12:15:40 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4XlGXg1qTMz1SGCR; Fri, 8 Nov 2024 19:13:55 +0800 (CST) Received: from kwepemf500004.china.huawei.com (unknown [7.202.181.242]) by mail.maildlp.com (Postfix) with ESMTPS id 787A81402CE; Fri, 8 Nov 2024 19:15:39 +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:38 +0800 From: Jie Hai To: , , , Nicolas Chautru , Maxime Coquelin , Amr Mokhtar CC: , , , Subject: [PATCH v5 02/25] app/bbdev: replace strtok with reentrant version Date: Fri, 8 Nov 2024 19:03:41 +0800 Message-ID: <20241108110404.18317-3-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: 0acdb9866756 ("test/bbdev: add FFT operations cases") Fixes: f714a18885a6 ("app/testbbdev: add test application for bbdev") Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- app/test-bbdev/test_bbdev_vector.c | 42 +++++++++++++++++------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/app/test-bbdev/test_bbdev_vector.c b/app/test-bbdev/test_bbdev_vector.c index 8b32850982c3..fbbdde70bdfc 100644 --- a/app/test-bbdev/test_bbdev_vector.c +++ b/app/test-bbdev/test_bbdev_vector.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "test_bbdev_vector.h" @@ -63,8 +64,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_r(tokens, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; @@ -98,7 +100,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_r(NULL, VALUE_DELIMITER, &sp); if (tok == NULL) break; @@ -324,8 +326,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_r(tokens, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; @@ -359,7 +362,7 @@ parse_turbo_flags(char *tokens, uint32_t *op_flags, *op_flags = *op_flags | op_flag_value; - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_r(NULL, VALUE_DELIMITER, &sp); if (tok == NULL) break; } @@ -399,9 +402,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_r(tokens, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; @@ -432,7 +436,7 @@ parse_expected_status(char *tokens, int *status, enum rte_bbdev_op_type op_type) return -1; } - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_r(NULL, VALUE_DELIMITER, &sp); if (tok == NULL) break; } @@ -932,6 +936,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; @@ -964,7 +969,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_r(token, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; for (i = 0; i < FFT_WIN_SIZE; i++) { @@ -972,7 +977,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_r(NULL, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; } @@ -1016,53 +1021,53 @@ parse_fft_params(const char *key_token, char *token, fft->output_depadded_size = (uint32_t) strtoul(token, &err, 0); ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; } else if (!strcmp(key_token, "cs_theta_0")) { - tok = strtok(token, VALUE_DELIMITER); + tok = strtok_r(token, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; for (i = 0; i < FFT_WIN_SIZE; i++) { fft->cs_theta_0[i] = (uint32_t) strtoul(tok, &err, 0); if (i < (FFT_WIN_SIZE - 1)) { - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_r(token, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; } } ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; } else if (!strcmp(key_token, "cs_theta_d")) { - tok = strtok(token, VALUE_DELIMITER); + tok = strtok_r(token, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; for (i = 0; i < FFT_WIN_SIZE; i++) { fft->cs_theta_d[i] = (uint32_t) strtoul(tok, &err, 0); if (i < (FFT_WIN_SIZE - 1)) { - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_r(token, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; } } ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; } else if (!strcmp(key_token, "time_offset")) { - tok = strtok(token, VALUE_DELIMITER); + tok = strtok_r(token, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; for (i = 0; i < FFT_WIN_SIZE; i++) { fft->time_offset[i] = (uint32_t) strtoul(tok, &err, 0); if (i < (FFT_WIN_SIZE - 1)) { - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_r(token, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; } } ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; } else if (!strcmp(key_token, "fft_window_width")) { - tok = strtok(token, VALUE_DELIMITER); + tok = strtok_r(token, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; for (i = 0; i < FFT_WIN_SIZE; i++) { if (i == 0) vector->fft_window_width_vec = (uint32_t) strtoul(tok, &err, 0); if (i < (FFT_WIN_SIZE - 1)) { - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_r(token, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; } @@ -1163,6 +1168,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; @@ -1172,10 +1178,10 @@ parse_entry(char *entry, struct test_bbdev_vector *vector) } /* get key */ - token = strtok(entry, ENTRY_DELIMITER); + token = strtok_r(entry, ENTRY_DELIMITER, &sp); key_token = token; /* get values for key */ - token = strtok(NULL, ENTRY_DELIMITER); + token = strtok_r(NULL, ENTRY_DELIMITER, &sp); if (key_token == NULL || token == NULL) { printf("Expected 'key = values' but was '%.40s'..\n", entry); -- 2.22.0