From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 48FD26CC3 for ; Tue, 8 May 2018 10:57:28 +0200 (CEST) X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 May 2018 01:57:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,377,1520924400"; d="scan'208";a="54094192" Received: from bricha3-mobl.ger.corp.intel.com ([10.237.221.55]) by orsmga001.jf.intel.com with SMTP; 08 May 2018 01:57:25 -0700 Received: by (sSMTP sendmail emulation); Tue, 08 May 2018 09:57:24 +0100 Date: Tue, 8 May 2018 09:57:23 +0100 From: Bruce Richardson To: Andy Green Cc: dev@dpdk.org Message-ID: <20180508085723.GA20636@bricha3-MOBL.ger.corp.intel.com> References: <152575364588.56689.3300796065057551728.stgit@localhost.localdomain> <152575377810.56689.13705223191364412484.stgit@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <152575377810.56689.13705223191364412484.stgit@localhost.localdomain> Organization: Intel Research and Development Ireland Ltd. User-Agent: Mutt/1.9.4 (2018-02-28) Subject: Re: [dpdk-dev] [PATCH 02/18] drivers: bus: pci: fix strncpy dangerous code 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: Tue, 08 May 2018 08:57:28 -0000 On Tue, May 08, 2018 at 12:29:38PM +0800, Andy Green wrote: > In function ‘pci_get_kernel_driver_by_path’, > inlined from ‘pci_scan_one.isra.1’ at /home/agreen/projects/dpdk/drivers/bus/pci/linux/pci.c:317:8: > /home/agreen/projects/dpdk/drivers/bus/pci/linux/pci.c:57:3: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=] > strncpy(dri_name, name + 1, strlen(name + 1) + 1); > --- > drivers/bus/pci/linux/pci.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c > index 4630a8057..b5bdfd33e 100644 > --- a/drivers/bus/pci/linux/pci.c > +++ b/drivers/bus/pci/linux/pci.c > @@ -54,7 +54,8 @@ pci_get_kernel_driver_by_path(const char *filename, char *dri_name) > > name = strrchr(path, '/'); > if (name) { > - strncpy(dri_name, name + 1, strlen(name + 1) + 1); > + strncpy(dri_name, name + 1, sizeof(dri_name) - 1); > + dri_name[sizeof(dri_name) - 1] = '\0'; > return 0; > } While this fix is correct, a better fix would be to use strlcpy from rte_string_fns.h. strlcpy(dri_name, name + 1, sizeof(dri_name)); Regards, /Bruce