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-stable] [PATCH v2 1/3] tests/kvargs: fix to consider empty elements as valid
Date: Fri, 27 Mar 2020 09:09:53 +0100 [thread overview]
Message-ID: <20200327080955.19571-2-olivier.matz@6wind.com> (raw)
In-Reply-To: <20200327080955.19571-1-olivier.matz@6wind.com>
Empty elements passed to the kvargs parser are silently
ignored. Examples of valid strings:
""
","
",,,,,,key=val,,,,"
Fix the unit tests to conform to this behavior.
Note: the test_invalid_kvargs() function is currently broken, which
explain why the tests were not failing. It is fixed in the next commit.
Fixes: e495f5435524 ("kvargs: add test case in app/test")
Cc: stable@dpdk.org
Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
app/test/test_kvargs.c | 37 +++++++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/app/test/test_kvargs.c b/app/test/test_kvargs.c
index a42056f36..d3db88a57 100644
--- a/app/test/test_kvargs.c
+++ b/app/test/test_kvargs.c
@@ -142,7 +142,7 @@ static int test_valid_kvargs(void)
valid_keys = valid_keys_list;
kvlist = rte_kvargs_parse(args, valid_keys);
if (kvlist == NULL) {
- printf("rte_kvargs_parse() error");
+ printf("rte_kvargs_parse() error\n");
goto fail;
}
if (strcmp(kvlist->pairs[0].value, "[0,1]") != 0) {
@@ -157,6 +157,40 @@ static int test_valid_kvargs(void)
}
rte_kvargs_free(kvlist);
+ /* test using empty string (it is valid) */
+ args = "";
+ kvlist = rte_kvargs_parse(args, NULL);
+ if (kvlist == NULL) {
+ printf("rte_kvargs_parse() error\n");
+ goto fail;
+ }
+ if (rte_kvargs_count(kvlist, NULL) != 0) {
+ printf("invalid count value\n");
+ goto fail;
+ }
+ rte_kvargs_free(kvlist);
+
+ /* test using empty elements (it is valid) */
+ args = "foo=1,,check=value2,,";
+ kvlist = rte_kvargs_parse(args, NULL);
+ if (kvlist == NULL) {
+ printf("rte_kvargs_parse() error\n");
+ goto fail;
+ }
+ if (rte_kvargs_count(kvlist, NULL) != 2) {
+ printf("invalid count value\n");
+ goto fail;
+ }
+ if (rte_kvargs_count(kvlist, "foo") != 1) {
+ printf("invalid count value for 'foo'\n");
+ goto fail;
+ }
+ if (rte_kvargs_count(kvlist, "check") != 1) {
+ printf("invalid count value for 'check'\n");
+ goto fail;
+ }
+ rte_kvargs_free(kvlist);
+
return 0;
fail:
@@ -179,7 +213,6 @@ static int test_invalid_kvargs(void)
const char *args_list[] = {
"wrong-key=x", /* key not in valid_keys_list */
"foo=1,foo=", /* empty value */
- "foo=1,,foo=2", /* empty key/value */
"foo=1,foo", /* no value */
"foo=1,=2", /* no key */
"foo=[1,2", /* no closing bracket in value */
--
2.25.1
next prev parent reply other threads:[~2020-03-27 8:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-19 4:38 [dpdk-stable] [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-stable] 答复: " wangyunjian
2020-03-27 8:09 ` [dpdk-stable] [PATCH v2 0/3] kvargs fixes Olivier Matz
2020-03-27 8:09 ` Olivier Matz [this message]
2020-03-27 8:09 ` [dpdk-stable] [PATCH v2 2/3] tests/kvargs: fix check of invalid cases Olivier Matz
2020-03-27 8:09 ` [dpdk-stable] [PATCH v2 3/3] kvargs: fix a heap buffer overflow when parsing list Olivier Matz
2020-03-27 15:16 ` [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-2-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).