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 B84E7C254 for ; Fri, 18 May 2018 14:16:10 +0200 (CEST) From: Andy Green To: stable@dpdk.org Date: Fri, 18 May 2018 20:16:06 +0800 Message-ID: <152664576682.32615.8482190211166561106.stgit@localhost.localdomain> In-Reply-To: <152664553026.32615.51601026908782839.stgit@localhost.localdomain> References: <152664553026.32615.51601026908782839.stgit@localhost.localdomain> User-Agent: StGit/unknown-version Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [dpdk-stable] [PATCH 2/4] bus/pci: fix size of driver name buffer X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 May 2018 12:16:10 -0000 Variable dri_name is a pointer and it is incorrect to use its size as the buffer size. Caller knows the buffer size and it is safer to pass it explicitly. Fixes: fe5f777b5383 ("bus/pci: replace strncpy by strlcpy") Cc: stable@dpdk.org Signed-off-by: Andy Green Reviewed-by: Andrew Rybchenko --- lib/librte_eal/linuxapp/eal/eal_pci.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index 876ba3819..f9fde3f07 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -94,7 +94,8 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev) } static int -pci_get_kernel_driver_by_path(const char *filename, char *dri_name) +pci_get_kernel_driver_by_path(const char *filename, char *dri_name, + size_t len) { int count; char path[PATH_MAX]; @@ -115,7 +116,7 @@ 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); + strlcpy(dri_name, name + 1, len); return 0; } @@ -369,7 +370,7 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus, /* parse driver */ snprintf(filename, sizeof(filename), "%s/driver", dirname); - ret = pci_get_kernel_driver_by_path(filename, driver); + ret = pci_get_kernel_driver_by_path(filename, driver, sizeof(driver)); if (ret < 0) { RTE_LOG(ERR, EAL, "Fail to get kernel driver\n"); free(dev);