DPDK patches and discussions
 help / color / mirror / Atom feed
From: Wei Huang <wei.huang@intel.com>
To: dev@dpdk.org, rosen.xu@intel.com, qi.z.zhang@intel.com
Cc: Wei Huang <wei.huang@intel.com>
Subject: [dpdk-dev] [PATCH v2 1/2] raw/ifpga: terminate string filled by readlink with null
Date: Thu, 29 Oct 2020 20:21:33 -0400
Message-ID: <1604017294-23479-2-git-send-email-wei.huang@intel.com> (raw)
In-Reply-To: <1604017294-23479-1-git-send-email-wei.huang@intel.com>

readlink() does not terminate string, add a null character at the end
of the string if readlink() succeeds.

Fixes: 9c006c45d0c5 ("raw/ifpga: scan PCIe BDF device tree")

Signed-off-by: Wei Huang <wei.huang@intel.com>
---
v2: fix coding style issue
---
 drivers/raw/ifpga/ifpga_rawdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c
index 0385514..f9de167 100644
--- a/drivers/raw/ifpga/ifpga_rawdev.c
+++ b/drivers/raw/ifpga/ifpga_rawdev.c
@@ -230,8 +230,9 @@ static int ifpga_rawdev_fill_info(struct ifpga_rawdev *ifpga_dev,
 	memset(link, 0, sizeof(link));
 	memset(link1, 0, sizeof(link1));
 	ret = readlink(path, link, (sizeof(link)-1));
-	if (ret == -1)
+	if ((ret < 0) || ((unsigned int)ret > (sizeof(link)-1)))
 		return -1;
+	link[ret] = 0;   /* terminate string with null character */
 	strlcpy(link1, link, sizeof(link1));
 	memset(ifpga_dev->parent_bdf, 0, 16);
 	point = strlen(link);
-- 
2.7.3


  reply	other threads:[~2020-10-30  1:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-30  0:21 [dpdk-dev] [PATCH v2 0/2] raw/ifpga: fix coverity defects Wei Huang
2020-10-30  0:21 ` Wei Huang [this message]
2020-10-30  6:56   ` [dpdk-dev] [PATCH v2 1/2] raw/ifpga: terminate string filled by readlink with null Zhang, Tianfei
2020-10-30  0:21 ` [dpdk-dev] [PATCH v2 2/2] raw/ifpga: use trusted buffer to free Wei Huang
2020-10-30  6:56   ` Zhang, Tianfei
2020-11-02 12:23 ` [dpdk-dev] [PATCH v2 0/2] raw/ifpga: fix coverity defects Zhang, Qi Z

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=1604017294-23479-2-git-send-email-wei.huang@intel.com \
    --to=wei.huang@intel.com \
    --cc=dev@dpdk.org \
    --cc=qi.z.zhang@intel.com \
    --cc=rosen.xu@intel.com \
    /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

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git