From patchwork Mon Nov 13 10:45:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134138 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DB2EA430AB; Mon, 13 Nov 2023 11:51:39 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 550EF40A7A; Mon, 13 Nov 2023 11:51:03 +0100 (CET) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id 0B7EF4064C for ; Mon, 13 Nov 2023 11:50:59 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4STR1W6h8LzMmn1; Mon, 13 Nov 2023 18:46:23 +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; Mon, 13 Nov 2023 18:50:57 +0800 From: Jie Hai To: , Wisam Jaddo CC: , , Subject: [PATCH 07/21] app/dpdk-test-flow-perf: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:36 +0800 Message-ID: <20231113104550.2138654-8-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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 function. Signed-off-by: Jie Hai --- app/test-flow-perf/main.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c index e224ef67983d..36e7c1d72019 100644 --- a/app/test-flow-perf/main.c +++ b/app/test-flow-perf/main.c @@ -602,6 +602,7 @@ read_meter_policy(char *prog, char *arg) { char *token; size_t i, j, k; + char *sp = NULL; j = 0; k = 0; @@ -612,9 +613,9 @@ read_meter_policy(char *prog, char *arg) token = strsep(&arg, ":\0"); } j = 0; - token = strtok(actions_str[0], ",\0"); + token = strtok_r(actions_str[0], ",\0", &sp); while (token == NULL && j < RTE_COLORS - 1) - token = strtok(actions_str[++j], ",\0"); + token = strtok_r(actions_str[++j], ",\0", &sp); while (j < RTE_COLORS && token != NULL) { for (i = 0; i < RTE_DIM(flow_options); i++) { if (!strcmp(token, flow_options[i].str)) { @@ -628,9 +629,9 @@ read_meter_policy(char *prog, char *arg) usage(prog); rte_exit(EXIT_SUCCESS, "Invalid colored actions\n"); } - token = strtok(NULL, ",\0"); + token = strtok_r(NULL, ",\0", &sp); while (!token && j < RTE_COLORS - 1) { - token = strtok(actions_str[++j], ",\0"); + token = strtok_r(actions_str[++j], ",\0", &sp); k = 0; } } @@ -641,6 +642,7 @@ args_parse(int argc, char **argv) { uint64_t pm, seed; uint64_t hp_conf; + char *sp = NULL; char **argvopt; uint32_t prio; char *token; @@ -804,7 +806,7 @@ args_parse(int argc, char **argv) RTE_FLOW_ACTION_TYPE_RAW_ENCAP ); - token = strtok(optarg, ","); + token = strtok_r(optarg, ",", &sp); while (token != NULL) { for (i = 0; i < RTE_DIM(flow_options); i++) { if (strcmp(flow_options[i].str, token) == 0) { @@ -817,7 +819,7 @@ args_parse(int argc, char **argv) rte_exit(EXIT_FAILURE, "Invalid encap item: %s\n", token); } - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); } printf(" / "); } @@ -828,7 +830,7 @@ args_parse(int argc, char **argv) RTE_FLOW_ACTION_TYPE_RAW_DECAP ); - token = strtok(optarg, ","); + token = strtok_r(optarg, ",", &sp); while (token != NULL) { for (i = 0; i < RTE_DIM(flow_options); i++) { if (strcmp(flow_options[i].str, token) == 0) { @@ -841,7 +843,7 @@ args_parse(int argc, char **argv) rte_exit(EXIT_FAILURE, "Invalid decap item %s\n", token); } - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); } printf(" / "); } @@ -910,10 +912,10 @@ args_parse(int argc, char **argv) uint16_t port_idx = 0; char *token; - token = strtok(optarg, ","); + token = strtok_r(optarg, ",", &sp); while (token != NULL) { dst_ports[port_idx++] = atoi(token); - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); } } if (strcmp(lgopts[opt_idx].name, "rxq") == 0) {