From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dispatch1-us1.ppe-hosted.com (dispatch1-us1.ppe-hosted.com [148.163.129.52]) by dpdk.org (Postfix) with ESMTP id DED3D2B87 for ; Mon, 4 Mar 2019 10:11:32 +0100 (CET) X-Virus-Scanned: Proofpoint Essentials engine Received: from webmail.solarflare.com (uk.solarflare.com [193.34.186.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mx1-us1.ppe-hosted.com (Proofpoint Essentials ESMTP Server) with ESMTPS id 79A85940070; Mon, 4 Mar 2019 09:11:30 +0000 (UTC) Received: from [192.168.38.17] (91.220.146.112) by ukex01.SolarFlarecom.com (10.17.10.4) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 4 Mar 2019 09:11:24 +0000 To: Stephen Hemminger CC: , Ferruh Yigit , Thomas Monjalon References: <20190228224754.26511-1-stephen@networkplumber.org> <20190228224754.26511-3-stephen@networkplumber.org> <8f248bd3-1ae6-c8a1-ee6e-37742bd6ea90@solarflare.com> <20190301104221.0d767d69@shemminger-XPS-13-9360> From: Andrew Rybchenko Message-ID: <7c2d3ade-44c1-1c7b-72ec-f7c66a7c7340@solarflare.com> Date: Mon, 4 Mar 2019 12:11:20 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <20190301104221.0d767d69@shemminger-XPS-13-9360> Content-Language: en-GB X-Originating-IP: [91.220.146.112] X-ClientProxiedBy: ocex03.SolarFlarecom.com (10.20.40.36) To ukex01.SolarFlarecom.com (10.17.10.4) X-TM-AS-Product-Ver: SMEX-12.5.0.1300-8.5.1010-24468.004 X-TM-AS-Result: No-6.942600-8.000000-10 X-TMASE-MatchedRID: oTBA/+sdKaYOwH4pD14DsPHkpkyUphL9UAjrAJWsTe9cU0dNErOD+t4z BXBaIg4KEd46bnfzirmjv3fWNoJmhBiQc5OixN2zSHCU59h5KrHeDfEPpXQu1Nr4gfya+A9UKhH e4lFqVUKkRgEg7nrRyuutPg6r34pTgiIO7Sf/7rE00dkxYNMRt4n4DdeD/uLNw7+XQ3Lk9nkahn O4XreYZseWUHEpxPJFHcN4x+ltYL2kwhnxbg1t+eQYBHVKqgDUfS0Ip2eEHny+qryzYw2E8LLn+ 0Vm71LcY2BsXShENnTXRyJeO9BGWwI56ngkfLUTKt4Wbnmw49zCZWeHIZvPhQTOunl/FdzHQxVR iNfaQgdu5Ij+/dUWAoUX/iPcznedARu/kADcVca0E8lIKFBUmy/+YRokhTQY/PYbz4olxT6khAn qbDXCvVbDabYiJxamiOcxOu8mckOZ93QdQacVBJt6SEDiCexopzaVCi5Krq9JS3dPTrxYzw== X-TM-AS-User-Approved-Sender: Yes X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--6.942600-8.000000 X-TMASE-Version: SMEX-12.5.0.1300-8.5.1010-24468.004 X-MDID: 1551690691-K6IhdNtgC2Em Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: Re: [dpdk-dev] [PATCH 2/2] ethdev: use strlcpy instead of snprintf on initialization X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Mar 2019 09:11:33 -0000 On 3/1/19 9:42 PM, Stephen Hemminger wrote: > On Fri, 1 Mar 2019 10:48:58 +0300 > Andrew Rybchenko wrote: > >> On 3/1/19 1:47 AM, Stephen Hemminger wrote: >>> Don't need to use snprintf for simple name copy. >>> >>> Signed-off-by: Stephen Hemminger >>> --- >>> lib/librte_ethdev/rte_ethdev.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c >>> index 95889ed206db..8bd54dcf58c1 100644 >>> --- a/lib/librte_ethdev/rte_ethdev.c >>> +++ b/lib/librte_ethdev/rte_ethdev.c >>> @@ -459,7 +459,7 @@ rte_eth_dev_allocate(const char *name) >>> } >>> >>> eth_dev = eth_dev_get(port_id); >>> - snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name); >>> + strlcpy(eth_dev->data->name, name, RTE_ETH_NAME_MAX_LEN); >> Why is sizeof() substituted with RTE_ETH_NAME_MAX_LEN? > Same thing, I just wanted to make the length obvious to the reader. > >> I thought that sizeof() is the first choice in such cases since it is a >> bit more >> safer vs possible changes in the code. >> >> BTW, wouldn't it be more friendly to check name length on entry and >> reject if it is too long? (and same for rte_eth_dev_create()) > It is impossible for name to long since since both structures are the same. Which structures? name is an input parameter of the function.