From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.warmcat.com (mail.warmcat.com [163.172.24.82]) by dpdk.org (Postfix) with ESMTP id 947031B84C for ; Sat, 12 May 2018 03:17:46 +0200 (CEST) To: "De Lara Guarch, Pablo" , "dev@dpdk.org" References: <152600304856.53146.9681482138854493833.stgit@localhost.localdomain> <152600315096.53146.4309625575083492451.stgit@localhost.localdomain> From: Andy Green Message-ID: <21a607a0-cb6d-bb47-110a-1fc73474f91b@warmcat.com> Date: Sat, 12 May 2018 09:17:38 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Subject: Re: [dpdk-dev] [PATCH v4 07/18] net/nfp/nfpcore: off-by-one and no NUL on strncpy use 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: Sat, 12 May 2018 01:17:46 -0000 On 05/11/2018 06:33 PM, De Lara Guarch, Pablo wrote: > > >> -----Original Message----- >> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Andy Green >> Sent: Friday, May 11, 2018 2:46 AM >> To: dev@dpdk.org >> Subject: [dpdk-dev] [PATCH v4 07/18] net/nfp/nfpcore: off-by-one and no NUL >> on strncpy use >> >> /home/agreen/projects/dpdk/drivers/net/nfp/nfpcore/nfp_resource.c: >> 76:2:error: ‘strncpy’ output may be truncated copying 8 bytes from a string of >> length 8 [-Werror=stringop-truncation] >> strncpy(name_pad, res->name, sizeof(name_pad)); >> >> Signed-off-by: Andy Green >> --- >> drivers/net/nfp/nfpcore/nfp_resource.c | 10 ++++++---- >> 1 file changed, 6 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c >> b/drivers/net/nfp/nfpcore/nfp_resource.c >> index e1df2b2e1..dd41fa4de 100644 >> --- a/drivers/net/nfp/nfpcore/nfp_resource.c >> +++ b/drivers/net/nfp/nfpcore/nfp_resource.c > > ... > >> - memset(name_pad, 0, NFP_RESOURCE_ENTRY_NAME_SZ); >> - strncpy(name_pad, res->name, sizeof(name_pad)); >> + memset(name_pad, 0, sizeof(name_pad)); >> + strlcpy(name_pad, res->name, sizeof(name_pad)); > > I think memset is not required, as strlcpy already null terminate the buffer. It seems required to keep it, because of the exciting code just below it: /* Search for a matching entry */ if (!memcmp(name_pad, NFP_RESOURCE_TBL_NAME "\0\0\0\0\0\0\0\0", 8)) { printf("Grabbing device lock not supported\n"); return -EOPNOTSUPP; } -Andy > ... > > Missing fixes line. > > Fixes: c7e9729da6b5 ("net/nfp: support CPP") > > Acked-by: Pablo de Lara >