[dpdk-dev] bus/pci: correct the earlier strlcpy conversion

Message ID 152636946035.95095.1840276672620244597.stgit@localhost.localdomain (mailing list archive)
State Accepted, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Andy Green May 15, 2018, 7:31 a.m. UTC
  Fixes: fe5f777b5383 ("bus/pci: replace strncpy by strlcpy")
Signed-off-by: Andy Green <andy@warmcat.com>
---
 drivers/bus/pci/linux/pci.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
  

Comments

Andrew Rybchenko May 15, 2018, 10:51 a.m. UTC | #1
On 05/15/2018 10:31 AM, Andy Green wrote:
> Fixes: fe5f777b5383 ("bus/pci: replace strncpy by strlcpy")
> Signed-off-by: Andy Green <andy@warmcat.com>

Reviewed-by: Andrew Rybchenko <arybchenko@solarflare.com>

Suggest to reword it as:

bus/pci: fix invalid size of driver name buffer

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.
  
Thomas Monjalon May 15, 2018, 1:19 p.m. UTC | #2
15/05/2018 12:51, Andrew Rybchenko:
> On 05/15/2018 10:31 AM, Andy Green wrote:
> > Fixes: fe5f777b5383 ("bus/pci: replace strncpy by strlcpy")
> > Signed-off-by: Andy Green <andy@warmcat.com>
> 
> Reviewed-by: Andrew Rybchenko <arybchenko@solarflare.com>
> 
> Suggest to reword it as:
> 
> bus/pci: fix invalid size of driver name buffer
> 
> 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.

Applied, thanks
  

Patch

diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c
index a73ee49c2..004600f1c 100644
--- a/drivers/bus/pci/linux/pci.c
+++ b/drivers/bus/pci/linux/pci.c
@@ -33,7 +33,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];
@@ -54,7 +55,7 @@  pci_get_kernel_driver_by_path(const char *filename, char *dri_name)
 
 	name = strrchr(path, '/');
 	if (name) {
-		strlcpy(dri_name, name + 1, sizeof(dri_name));
+		strlcpy(dri_name, name + 1, len);
 		return 0;
 	}
 
@@ -314,7 +315,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);