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 7E2BB45D7C; Fri, 22 Nov 2024 12:12:23 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 986C0433B3; Fri, 22 Nov 2024 12:11:46 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 3115F4338B for ; Fri, 22 Nov 2024 12:11:39 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4XvsmP4sypz69b5; Fri, 22 Nov 2024 19:08:53 +0800 (CST) Received: from kwepemf500004.china.huawei.com (unknown [7.202.181.242]) by mail.maildlp.com (Postfix) with ESMTPS id 01AD6180106; Fri, 22 Nov 2024 19:11:38 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) 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, 22 Nov 2024 19:11:37 +0800 From: Jie Hai To: , , , Srikanth Yalavarthi , Anup Prabhu CC: , , , Subject: [PATCH v6 06/25] app/test-mldev: replace strtok with reentrant version Date: Fri, 22 Nov 2024 19:04:38 +0800 Message-ID: <20241122110458.2156907-7-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241122110458.2156907-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20241122110458.2156907-1-haijie1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.90.30.45] 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: bbd272edcb14 ("app/mldev: add ordered inferences") Fixes: 28a4a819c850 ("app/mldev: improve checks for invalid options") Fixes: da6793390596 ("app/mldev: support inference validation") Fixes: f6661e6d9a3a ("app/mldev: validate model operations") Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- app/test-mldev/ml_options.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/test-mldev/ml_options.c b/app/test-mldev/ml_options.c index 320f6325ae67..1033444de0e1 100644 --- a/app/test-mldev/ml_options.c +++ b/app/test-mldev/ml_options.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "ml_common.h" #include "ml_test.h" @@ -76,12 +77,12 @@ ml_parse_models(struct ml_options *opt, const char *arg) { const char *delim = ","; char models[PATH_MAX]; - char *token; + char *token, *sp = NULL; int ret = 0; strlcpy(models, arg, PATH_MAX); - token = strtok(models, delim); + token = strtok_r(models, delim, &sp); while (token != NULL) { if (opt->nb_filelist >= ML_TEST_MAX_MODELS) { ml_err("Exceeded model count, max = %d\n", ML_TEST_MAX_MODELS); @@ -92,7 +93,7 @@ ml_parse_models(struct ml_options *opt, const char *arg) strlcpy(opt->filelist[opt->nb_filelist].model, token, PATH_MAX); opt->nb_filelist++; - token = strtok(NULL, delim); + token = strtok_r(NULL, delim, &sp); } if (opt->nb_filelist == 0) { @@ -108,7 +109,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg) { const char *delim = ","; char filelist[PATH_MAX]; - char *token; + char *token, *sp = NULL; if (opt->nb_filelist >= ML_TEST_MAX_MODELS) { ml_err("Exceeded filelist count, max = %d\n", ML_TEST_MAX_MODELS); @@ -118,7 +119,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg) strlcpy(filelist, arg, PATH_MAX); /* model */ - token = strtok(filelist, delim); + token = strtok_r(filelist, delim, &sp); if (token == NULL) { ml_err("Invalid filelist, model not specified = %s\n", arg); return -EINVAL; @@ -126,7 +127,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg) strlcpy(opt->filelist[opt->nb_filelist].model, token, PATH_MAX); /* input */ - token = strtok(NULL, delim); + token = strtok_r(NULL, delim, &sp); if (token == NULL) { ml_err("Invalid filelist, input not specified = %s\n", arg); return -EINVAL; @@ -134,7 +135,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg) strlcpy(opt->filelist[opt->nb_filelist].input, token, PATH_MAX); /* output */ - token = strtok(NULL, delim); + token = strtok_r(NULL, delim, &sp); if (token == NULL) { ml_err("Invalid filelist, output not specified = %s\n", arg); return -EINVAL; @@ -142,14 +143,14 @@ ml_parse_filelist(struct ml_options *opt, const char *arg) strlcpy(opt->filelist[opt->nb_filelist].output, token, PATH_MAX); /* reference - optional */ - token = strtok(NULL, delim); + token = strtok_r(NULL, delim, &sp); if (token != NULL) strlcpy(opt->filelist[opt->nb_filelist].reference, token, PATH_MAX); else memset(opt->filelist[opt->nb_filelist].reference, 0, PATH_MAX); /* check for extra tokens */ - token = strtok(NULL, delim); + token = strtok_r(NULL, delim, &sp); if (token != NULL) { ml_err("Invalid filelist. Entries > 4\n."); return -EINVAL; -- 2.33.0