[dpdk-dev,v4,03/18] bus/pci: replace strncpy dangerous code

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

Checks

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

Commit Message

Andy Green May 11, 2018, 1:45 a.m. UTC
  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);

Signed-off-by: Andy Green <andy@warmcat.com>
Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 drivers/bus/pci/linux/pci.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

De Lara Guarch, Pablo May 11, 2018, 8:17 a.m. UTC | #1
> -----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 03/18] bus/pci: replace strncpy dangerous code

> 

> 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);

> 

> Signed-off-by: Andy Green <andy@warmcat.com>

> Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>


Forgot to say that this needs fixes lines and cc stable.

Fixes: d9a8cd9595f2 ("pci: add kernel driver type")
Cc: stable@dpdk.org
  

Patch

diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c
index 4630a8057..a73ee49c2 100644
--- a/drivers/bus/pci/linux/pci.c
+++ b/drivers/bus/pci/linux/pci.c
@@ -54,7 +54,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, sizeof(dri_name));
 		return 0;
 	}