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 7CC6445B9C; Tue, 22 Oct 2024 08:51:44 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1D2C5402BC; Tue, 22 Oct 2024 08:51:44 +0200 (CEST) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 238AA4029A for ; Tue, 22 Oct 2024 08:51:42 +0200 (CEST) Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4XXjTb61rVz10Nvs; Tue, 22 Oct 2024 14:49:39 +0800 (CST) Received: from dggpeml500024.china.huawei.com (unknown [7.185.36.10]) by mail.maildlp.com (Postfix) with ESMTPS id 48794140384; Tue, 22 Oct 2024 14:51:40 +0800 (CST) Received: from [10.67.121.161] (10.67.121.161) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 22 Oct 2024 14:51:40 +0800 Message-ID: <282a31cf-7ccd-4de3-99b9-687287b20e24@huawei.com> Date: Tue, 22 Oct 2024 14:51:39 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Use of strtok() in dpdk code To: Stephen Hemminger , Isaac Boukris , Thomas Monjalon CC: , "haijie1@huawei.com >> Jie Hai" , References: <20241021180820.48c7bffd@hermes.local> Content-Language: en-US From: fengchengwen In-Reply-To: <20241021180820.48c7bffd@hermes.local> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.121.161] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500024.china.huawei.com (7.185.36.10) 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 On 2024/10/22 9:08, Stephen Hemminger wrote: > On Mon, 21 Oct 2024 21:30:02 +0300 > Isaac Boukris wrote: > >> Hello, >> >> I was debugging a crash resulting from strtok() returning NULL >> unexpectedly (string still had tokens and delimiters), and the only >> explanation I could come up with was that strtok is thread-unsafe and >> another thread could have been calling it at the same time, and so I >> changed it to use strtok_r(). >> >> That said, the only other possible use of strtok() that I could find >> was in the dpdk code (telemetry), which brings me to my question, >> should we consider changing all occurrences to strtok_r() or am I >> missing something? there seem to be quite some in non-initialization >> code. >> >> Thanks! > > > Most of the uses are in tests and other single threaded code. > In general, simpler just to use strtok_r everywhere and not worry about it. > Similar to not using sprintf() and instead using snprintf(). I'm afraid I can't agree. DPDK is just a SDK, it's not an application (although DPDK provided simple examples). Many code will developped based on DPDK, we can't predict how it was implemented. So there maybe a DPDK thread and a application thread both invoke strtok(). >From this point of view, I hope that DPDK solves some of the reentrant problems of such C functions (e.g. strtok()\strerror()). Actually, we've try to solve before, but unfortunately it wasn't merged. 1\ strtok(): https://inbox.dpdk.org/dev/20231114110006.91148-1-haijie1@huawei.com/T/#u 2\ strerror(): https://inbox.dpdk.org/dev/20231114123552.398072-1-huangdengdui@huawei.com/T/#u > > Some code scanners like codeql also flag this.