patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Andy Green <andy@warmcat.com>
To: stable@dpdk.org
Subject: [dpdk-stable] [PATCH 2/4] bus/pci: fix size of driver name buffer
Date: Fri, 18 May 2018 20:16:06 +0800	[thread overview]
Message-ID: <152664576682.32615.8482190211166561106.stgit@localhost.localdomain> (raw)
In-Reply-To: <152664553026.32615.51601026908782839.stgit@localhost.localdomain>

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

  parent reply	other threads:[~2018-05-18 12:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-01 10:49 [dpdk-stable] please help backporting some patches to LTS release 16.11.7 luca.boccassi
2018-05-07  2:08 ` Chen, Junjie J
2018-05-08  9:50   ` Luca Boccassi
2018-05-18  9:47 ` luca.boccassi
2018-05-18 12:15   ` [dpdk-stable] [PATCH 0/4] 16.11 Requested backports Andy Green
2018-05-18 12:16     ` [dpdk-stable] [PATCH 1/4] eal: support strlcpy function Andy Green
2018-05-18 12:16     ` Andy Green [this message]
2018-05-18 12:16     ` [dpdk-stable] [PATCH 3/4] net/qede: fix strncpy Andy Green
2018-05-18 12:16     ` [dpdk-stable] [PATCH 4/4] net/qede: replace strncpy by strlcpy Andy Green
2018-05-18 12:48     ` [dpdk-stable] [PATCH 0/4] 16.11 Requested backports Luca Boccassi
2018-05-25 17:24   ` [dpdk-stable] please help backporting some patches to LTS release 16.11.7 luca.boccassi
2018-05-29 21:59     ` Shaikh, Shahed
2018-05-29 22:55       ` Luca Boccassi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=152664576682.32615.8482190211166561106.stgit@localhost.localdomain \
    --to=andy@warmcat.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).