DPDK patches and discussions
 help / color / mirror / Atom feed
From: Olivier Matz <olivier.matz@6wind.com>
To: wangyunjian@huawei.com
Cc: dev@dpdk.org, jerry.lilijun@huawei.com, olivier.matz@6wind.com,
	stable@dpdk.org, xudingke@huawei.com
Subject: [dpdk-dev] [PATCH v2 3/3] kvargs: fix a heap buffer overflow when parsing list
Date: Fri, 27 Mar 2020 09:09:55 +0100	[thread overview]
Message-ID: <20200327080955.19571-4-olivier.matz@6wind.com> (raw)
In-Reply-To: <20200327080955.19571-1-olivier.matz@6wind.com>

From: Yunjian Wang <wangyunjian@huawei.com>

When the input string is "key=[", the ending '\0' is replaced
by a ',', leading to a heap buffer overflow.

Check the content of ctx1 to avoid this problem.

Fixes: cc0579f2339a ("kvargs: support list value")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
 app/test/test_kvargs.c         | 1 +
 lib/librte_kvargs/rte_kvargs.c | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/app/test/test_kvargs.c b/app/test/test_kvargs.c
index f823b771f..2a2dae43a 100644
--- a/app/test/test_kvargs.c
+++ b/app/test/test_kvargs.c
@@ -217,6 +217,7 @@ static int test_invalid_kvargs(void)
 		"foo=1,=2",        /* no key */
 		"foo=[1,2",        /* no closing bracket in value */
 		",=",              /* also test with a smiley */
+		"foo=[",           /* no value in list and no closing bracket */
 		NULL };
 	const char **args;
 	const char *valid_keys_list[] = { "foo", "check", NULL };
diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c
index d39332999..1d815dcd9 100644
--- a/lib/librte_kvargs/rte_kvargs.c
+++ b/lib/librte_kvargs/rte_kvargs.c
@@ -50,6 +50,8 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
 			/* Find the end of the list. */
 			while (str[strlen(str) - 1] != ']') {
 				/* Restore the comma erased by strtok_r(). */
+				if (ctx1[0] == '\0')
+					return -1; /* no closing bracket */
 				str[strlen(str)] = ',';
 				/* Parse until next comma. */
 				str = strtok_r(NULL, RTE_KVARGS_PAIRS_DELIM, &ctx1);
-- 
2.25.1


  parent reply	other threads:[~2020-03-27  8:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-19  4:38 [dpdk-dev] [PATCH] kvargs: fix a heap-buffer-overflow when detect list wangyunjian
2020-03-25 16:31 ` Olivier Matz
2020-03-26 10:01   ` [dpdk-dev] 答复: " wangyunjian
2020-03-27  8:09 ` [dpdk-dev] [PATCH v2 0/3] kvargs fixes Olivier Matz
2020-03-27  8:09   ` [dpdk-dev] [PATCH v2 1/3] tests/kvargs: fix to consider empty elements as valid Olivier Matz
2020-03-27  8:09   ` [dpdk-dev] [PATCH v2 2/3] tests/kvargs: fix check of invalid cases Olivier Matz
2020-03-27  8:09   ` Olivier Matz [this message]
2020-03-27 15:16   ` [dpdk-dev] [dpdk-stable] [PATCH v2 0/3] kvargs fixes David Marchand
2020-03-27 17:12     ` David Marchand

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=20200327080955.19571-4-olivier.matz@6wind.com \
    --to=olivier.matz@6wind.com \
    --cc=dev@dpdk.org \
    --cc=jerry.lilijun@huawei.com \
    --cc=stable@dpdk.org \
    --cc=wangyunjian@huawei.com \
    --cc=xudingke@huawei.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).