DPDK patches and discussions
 help / color / mirror / Atom feed
From: Pablo de Lara <pablox.de.lara.guarch@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH] string: fix potential seg fault on snprintf
Date: Fri, 27 Jun 2014 12:04:57 +0100	[thread overview]
Message-ID: <1403867097-18848-1-git-send-email-pablox.de.lara.guarch@intel.com> (raw)

From: Pablo de Lara <pablo.de.lara.guarch@intel.com>

Several functions did not check if destination buffer, used
in snprintf was a non-NULL pointer.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 examples/cmdline/parse_obj_list.c            |    3 +++
 lib/librte_cmdline/cmdline_parse_etheraddr.c |    3 +++
 lib/librte_cmdline/cmdline_parse_num.c       |    2 +-
 lib/librte_cmdline/cmdline_parse_portlist.c  |    4 ++++
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c    |    3 +++
 5 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/examples/cmdline/parse_obj_list.c b/examples/cmdline/parse_obj_list.c
index 2625ca3..97dfa09 100644
--- a/examples/cmdline/parse_obj_list.c
+++ b/examples/cmdline/parse_obj_list.c
@@ -157,6 +157,9 @@ int complete_get_elt_obj_list(cmdline_parse_token_hdr_t *tk,
 int get_help_obj_list(__attribute__((unused)) cmdline_parse_token_hdr_t *tk,
 		      char *dstbuf, unsigned int size)
 {
+	if (!dstbuf)
+		return -1;
+
 	snprintf(dstbuf, size, "Obj-List");
 	return 0;
 }
diff --git a/lib/librte_cmdline/cmdline_parse_etheraddr.c b/lib/librte_cmdline/cmdline_parse_etheraddr.c
index 5285c40..774b167 100644
--- a/lib/librte_cmdline/cmdline_parse_etheraddr.c
+++ b/lib/librte_cmdline/cmdline_parse_etheraddr.c
@@ -170,6 +170,9 @@ cmdline_get_help_etheraddr(__attribute__((unused)) cmdline_parse_token_hdr_t *tk
 {
 	int ret;
 
+	if (!dstbuf)
+		return -1;
+
 	ret = snprintf(dstbuf, size, "Ethernet address");
 	if (ret < 0)
 		return -1;
diff --git a/lib/librte_cmdline/cmdline_parse_num.c b/lib/librte_cmdline/cmdline_parse_num.c
index 0b9e4d0..26ba5ef 100644
--- a/lib/librte_cmdline/cmdline_parse_num.c
+++ b/lib/librte_cmdline/cmdline_parse_num.c
@@ -349,7 +349,7 @@ cmdline_get_help_num(cmdline_parse_token_hdr_t *tk, char *dstbuf, unsigned int s
 	struct cmdline_token_num_data nd;
 	int ret;
 
-	if (!tk)
+	if (!tk || !dstbuf)
 		return -1;
 
 	memcpy(&nd, &((struct cmdline_token_num *)tk)->num_data, sizeof(nd));
diff --git a/lib/librte_cmdline/cmdline_parse_portlist.c b/lib/librte_cmdline/cmdline_parse_portlist.c
index 7eac05c..8e3521a 100644
--- a/lib/librte_cmdline/cmdline_parse_portlist.c
+++ b/lib/librte_cmdline/cmdline_parse_portlist.c
@@ -163,6 +163,10 @@ cmdline_get_help_portlist(__attribute__((unused)) cmdline_parse_token_hdr_t *tk,
 		char *dstbuf, unsigned int size)
 {
 	int ret;
+
+	if (!dstbuf)
+		return -1;
+
 	ret = snprintf(dstbuf, size, "range of ports as 3,4-6,8-19,20");
 	if (ret < 0)
 		return -1;
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 7e62266..ec0ba42 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -211,6 +211,9 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,
 	DIR *dir;
 	char dirname[PATH_MAX];
 
+	if (!dstbuf)
+		return -1;
+
 	/* depending on kernel version, uio can be located in uio/uioX
 	 * or uio:uioX */
 
-- 
1.7.0.7

             reply	other threads:[~2014-06-27 11:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-27 11:04 Pablo de Lara [this message]
2014-06-27 11:30 ` Olivier MATZ
2014-06-27 12:13   ` De Lara Guarch, Pablo
2014-06-27 12:34     ` Olivier MATZ
2014-06-27 16:36       ` Richardson, Bruce
2014-06-30  7:41         ` Olivier MATZ
2014-06-30 16:48           ` Richardson, Bruce

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=1403867097-18848-1-git-send-email-pablox.de.lara.guarch@intel.com \
    --to=pablox.de.lara.guarch@intel.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).