DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jianfeng Tan <jianfeng.tan@intel.com>
To: dev@dpdk.org
Cc: yuanhan.liu@linux.intel.com, huawei.xie@intel.com,
	john.mcnamara@intel.com, Jianfeng Tan <jianfeng.tan@intel.com>
Subject: [dpdk-dev] [PATCH 4/4] net/virtio-user: fix string unterminated
Date: Wed, 29 Jun 2016 09:05:36 +0000	[thread overview]
Message-ID: <1467191137-65087-5-git-send-email-jianfeng.tan@intel.com> (raw)
In-Reply-To: <1467191137-65087-1-git-send-email-jianfeng.tan@intel.com>

When use strcpy() to copy string with length exceeding the last
parameter of strcpy(), it may lead to the destination string
unterminated.

We replaced strncpy with snprintf to make sure it's NULL terminated.

Coverity issue: 127476

Fixes: ce2eabdd43ec ("net/virtio-user: add virtual device")

Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index 1b1e5bf..376c9cf 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -181,7 +181,7 @@ int
 virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 		     int cq, int queue_size, const char *mac)
 {
-	strncpy(dev->path, path, PATH_MAX);
+	snprintf(dev->path, PATH_MAX, "%s", path);
 	dev->max_queue_pairs = queues;
 	dev->queue_pairs = 1; /* mq disabled by default */
 	dev->queue_size = queue_size;
-- 
2.1.4

      parent reply	other threads:[~2016-06-29  9:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-29  9:05 [dpdk-dev] [PATCH 0/4] net/virtio-user: fix coverity issues Jianfeng Tan
2016-06-29  9:05 ` [dpdk-dev] [PATCH 1/4] net/virtio-user: fix return value not checked Jianfeng Tan
2016-07-01  2:15   ` Yuanhan Liu
2016-07-05 10:14     ` Tan, Jianfeng
2016-07-05 11:31       ` Yuanhan Liu
2016-06-29  9:05 ` [dpdk-dev] [PATCH 2/4] net/virtio-user: fix string overflow Jianfeng Tan
2016-06-29  9:05 ` [dpdk-dev] [PATCH 3/4] net/virtio-user: fix resource leaks Jianfeng Tan
2016-06-29  9:05 ` Jianfeng Tan [this message]

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=1467191137-65087-5-git-send-email-jianfeng.tan@intel.com \
    --to=jianfeng.tan@intel.com \
    --cc=dev@dpdk.org \
    --cc=huawei.xie@intel.com \
    --cc=john.mcnamara@intel.com \
    --cc=yuanhan.liu@linux.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
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).