From: Ferruh Yigit Subject: Re: [PATCH 2/2] ethdev: use strlcpy instead of snprintf on initialization Date: Wed, 6 Mar 2019 15:55:10 +0000 Message-ID: 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> <7c2d3ade-44c1-1c7b-72ec-f7c66a7c7340@solarflare.com> <20190304111210.344a7142@shemminger-XPS-13-9360> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: dev@dpdk.org, Thomas Monjalon To: Stephen Hemminger , Andrew Rybchenko Return-path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id B0B2A5F1B for ; Wed, 6 Mar 2019 16:55:15 +0100 (CET) In-Reply-To: <20190304111210.344a7142@shemminger-XPS-13-9360> Content-Language: en-US List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On 3/4/2019 7:12 PM, Stephen Hemminger wrote: > On Mon, 4 Mar 2019 12:11:20 +0300 > Andrew Rybchenko wrote: > >> 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. >> > > Sorry my confusion, that was in patch 1. Only concern is keep using "sizeof(eth_dev->data->name)" or RTE_ETH_NAME_MAX_LEN, both are correct but I agree with Andrew about using sizeof. Stephen, Would you be OK if I update it to sizeof() while merging, so I can merge them? Thanks, ferruh