DPDK patches and discussions
 help / color / mirror / Atom feed
From: Gaetan Rivet <gaetan.rivet@6wind.com>
To: dev@dpdk.org
Cc: Gaetan Rivet <gaetan.rivet@6wind.com>
Subject: [dpdk-dev] [PATCH] eal: fix off-by-one error in hotplug add
Date: Fri,  4 Aug 2017 17:30:23 +0200	[thread overview]
Message-ID: <1501860623-16747-1-git-send-email-gaetan.rivet@6wind.com> (raw)

snprintf returns the length it would have written had the given length
been enough, *terminating null byte excluded*.

It will however limit the length of its writing to given length minus
one, and always put a terminating null-byte at the end of the string.

This must be taken into account when calculating the total length of the
device declaration string.

Fixes: 3054036f054a ("eal: fix possible crash in hotplug")

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---

Charybdis -> Scylla

 lib/librte_eal/common/eal_common_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index fc8a4d2..e251275 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -133,7 +133,7 @@ full_dev_name(const char *bus, const char *dev, const char *args)
 	char *name;
 	size_t len;
 
-	len = snprintf(NULL, 0, "%s:%s,%s", bus, dev, args);
+	len = snprintf(NULL, 0, "%s:%s,%s", bus, dev, args) + 1;
 	name = calloc(1, len);
 	if (name == NULL) {
 		RTE_LOG(ERR, EAL, "Could not allocate full device name\n");
-- 
2.1.4

             reply	other threads:[~2017-08-04 15:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-04 15:30 Gaetan Rivet [this message]
2017-08-04 16:12 ` Thomas Monjalon

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=1501860623-16747-1-git-send-email-gaetan.rivet@6wind.com \
    --to=gaetan.rivet@6wind.com \
    --cc=dev@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).