From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by dpdk.org (Postfix) with ESMTP id 7B5542B98 for ; Mon, 4 Mar 2019 20:12:14 +0100 (CET) Received: by mail-pf1-f193.google.com with SMTP id u9so3697537pfn.1 for ; Mon, 04 Mar 2019 11:12:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KijSib8M4e05SI1p0ZwGmKgDAkcA3pERVIBpLhJj9HA=; b=zfdEP2Dr7KbjcPFwyNU4TjcmiKCm1Y31SloCq9Gjx4hutrAuGyCzVAnOz+h0U1PVZg 1Y8Q3L4B+23F94REll4Mn2EPK7D5rZlSoItQvegSuTl+XYBWaTtzeTsVN2yiZSuDisUQ 5eplnZ7TGG61jOg9BsxVCNlM/SU1J9ahjWkTbsa8p10xtSyKn3+yGu3kJsWKZ6ryTqjX FoEx10pNJIVgDhq2+LrhabHlU4XoJfY+c3lUNgr53p5mGPyONZJRPSy5rqxpncUi9XT1 84XPqMooo4pqM8kgLGoVo7JDyNtY4mZKTtvtlPhVHbQv0xKxFvDo6k6TVK6Wuqmlgqct yFaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KijSib8M4e05SI1p0ZwGmKgDAkcA3pERVIBpLhJj9HA=; b=Tr8uW0u1Sp6A2bFRA2fB+z9e3+6nRTC3OEDcdyDcPo7kVsLts3MmlD3gzhO2o2OYet OkKCOZGiXS3iTCRlD89KI0WF/im/VEC0V8Em5L0BsLms2oVOXJ9LpyMBgTUG585NleOX lVRrwHyRGgrzSqK2d//+1AV7qON/rdELHTWcbS+eP5b5F1KfNwttlcVVfrAGiTuTcA2o 6triXitPC3kJrPgYcLUe6lvbQgCr82Oz13zS0lcJRcDWkAoQM3RI9bRoEzLqgORTzz1R sw0+LUtIUqKUqHnnt1glNwLGqKiV1U3oeENZs3ORQ5D39PCwzmUmKkktlne3G+rxt7c9 UBhQ== X-Gm-Message-State: APjAAAWF57YjQVrYb2S5FAtNO6K+wHqwpKtOJ8hXojwhFHK8faFw0aPa J5WXmnRgHNIKLynN2zGiTa3m3g== X-Google-Smtp-Source: APXvYqy62pDHApOJJCJhzMFP9YE+1h46AfptkoWrejsxRyZga7BhVhbgjmG+iYopnzctuml5tKhEwg== X-Received: by 2002:a63:545f:: with SMTP id e31mr19431424pgm.409.1551726733631; Mon, 04 Mar 2019 11:12:13 -0800 (PST) Received: from shemminger-XPS-13-9360 ([167.220.104.59]) by smtp.gmail.com with ESMTPSA id f192sm12107876pfc.180.2019.03.04.11.12.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Mar 2019 11:12:13 -0800 (PST) Date: Mon, 4 Mar 2019 11:12:10 -0800 From: Stephen Hemminger To: Andrew Rybchenko Cc: , Ferruh Yigit , Thomas Monjalon Message-ID: <20190304111210.344a7142@shemminger-XPS-13-9360> In-Reply-To: <7c2d3ade-44c1-1c7b-72ec-f7c66a7c7340@solarflare.com> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 19:12:14 -0000 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.