From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <andy@warmcat.com> Received: from mail.warmcat.com (mail.warmcat.com [163.172.24.82]) by dpdk.org (Postfix) with ESMTP id D1DF7AAD6 for <stable@dpdk.org>; Fri, 18 May 2018 13:38:02 +0200 (CEST) From: Andy Green <andy@warmcat.com> To: stable@dpdk.org Date: Fri, 18 May 2018 19:37:58 +0800 Message-ID: <152664347890.25528.4168346444814519580.stgit@localhost.localdomain> In-Reply-To: <152664333397.25528.18140247166845268675.stgit@localhost.localdomain> References: <152664333397.25528.18140247166845268675.stgit@localhost.localdomain> User-Agent: StGit/unknown-version Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [dpdk-stable] [PATCH 2/5] 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 <stable.dpdk.org> List-Unsubscribe: <https://dpdk.org/ml/options/stable>, <mailto:stable-request@dpdk.org?subject=unsubscribe> List-Archive: <http://dpdk.org/ml/archives/stable/> List-Post: <mailto:stable@dpdk.org> List-Help: <mailto:stable-request@dpdk.org?subject=help> List-Subscribe: <https://dpdk.org/ml/listinfo/stable>, <mailto:stable-request@dpdk.org?subject=subscribe> X-List-Received-Date: Fri, 18 May 2018 11:38:03 -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 <andy@warmcat.com> Reviewed-by: Andrew Rybchenko <arybchenko@solarflare.com> --- drivers/bus/pci/linux/pci.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c index 5da6728fb..52b3e21fe 100644 --- a/drivers/bus/pci/linux/pci.c +++ b/drivers/bus/pci/linux/pci.c @@ -62,7 +62,8 @@ extern struct rte_pci_bus rte_pci_bus; 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]; @@ -83,7 +84,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; } @@ -339,7 +340,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) /* 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);