summaryrefslogtreecommitdiff
path: root/lib/librte_cmdline
diff options
context:
space:
mode:
authorWenzhuo Lu <wenzhuo.lu@intel.com>2017-04-25 11:11:25 +0800
committerThomas Monjalon <thomas@monjalon.net>2017-05-01 00:16:36 +0200
commit9b3fbb051d2e98161b68c8f5c60331170be7b853 (patch)
tree30706fa548de3799c90395a483fda410f85b45c1 /lib/librte_cmdline
parentf5b4a9aa02dd39de1aa7f213d2bec61f2c7b1aee (diff)
downloaddpdk-next-eventdev-9b3fbb051d2e98161b68c8f5c60331170be7b853.zip
dpdk-next-eventdev-9b3fbb051d2e98161b68c8f5c60331170be7b853.tar.gz
dpdk-next-eventdev-9b3fbb051d2e98161b68c8f5c60331170be7b853.tar.xz
cmdline: fix parsing
When parsing a CLI, all the CLI instances are checked one by one. Even if an instance already matches the CLI, the parsing will not stop for ambiguous check. The problem is that the following check may change the parsing result of the previous one even if the following instance doesn't match. Use a temporary validate for the parsing result when trying to match an instance and only store the result when it matches, so the previous result has no chance to be changed. Fixes: af75078fece3 ("first public release") Cc: stable@dpdk.org Signed-off-by: Wenzhuo Lu <wenzhuo.lu@intel.com> Acked-by: Olivier Matz <olivier.matz@6wind.com>
Diffstat (limited to 'lib/librte_cmdline')
-rw-r--r--lib/librte_cmdline/cmdline_parse.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/librte_cmdline/cmdline_parse.c b/lib/librte_cmdline/cmdline_parse.c
index 763c286..b814880 100644
--- a/lib/librte_cmdline/cmdline_parse.c
+++ b/lib/librte_cmdline/cmdline_parse.c
@@ -258,7 +258,7 @@ cmdline_parse(struct cmdline *cl, const char * buf)
union {
char buf[CMDLINE_PARSE_RESULT_BUFSIZE];
long double align; /* strong alignment constraint for buf */
- } result;
+ } result, tmp_result;
cmdline_parse_token_hdr_t *dyn_tokens[CMDLINE_PARSE_DYNAMIC_TOKENS];
void (*f)(void *, struct cmdline *, void *) = NULL;
void *data = NULL;
@@ -321,14 +321,16 @@ cmdline_parse(struct cmdline *cl, const char * buf)
debug_printf("INST %d\n", inst_num);
/* fully parsed */
- tok = match_inst(inst, buf, 0, result.buf, sizeof(result.buf),
- &dyn_tokens);
+ tok = match_inst(inst, buf, 0, tmp_result.buf,
+ sizeof(tmp_result.buf), &dyn_tokens);
if (tok > 0) /* we matched at least one token */
err = CMDLINE_PARSE_BAD_ARGS;
else if (!tok) {
debug_printf("INST fully parsed\n");
+ memcpy(&result, &tmp_result,
+ sizeof(result));
/* skip spaces */
while (isblank2(*curbuf)) {
curbuf++;