diff options
author | 2017-03-15 09:52:19 -0400 | |
---|---|---|
committer | 2017-03-15 09:52:50 -0400 | |
commit | 7c0858e2a40a5e496ed39a815566ff47aa2fc2be (patch) | |
tree | a26ca47383e3aeef45efc7e2ede902376a585e6c /src/vpp/api | |
parent | e101e1f52f1da71575588fac30b984a0e94fb5a7 (diff) |
Fix binary-api cmd/arg split logic
Change-Id: If3dbce830684b5eab8944519424074b03cc7d703
Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/vpp/api')
-rw-r--r-- | src/vpp/api/api_main.c | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/src/vpp/api/api_main.c b/src/vpp/api/api_main.c index a59524cf..d48e4eff 100644 --- a/src/vpp/api/api_main.c +++ b/src/vpp/api/api_main.c @@ -84,25 +84,20 @@ api_command_fn (vlib_main_t * vm, vam->vl_input_queue = am->shmem_hdr->vl_input_queue; -#ifdef __COVERITY__ - /* - * Convince Coverity that it's not a NULL pointer... - * Done once for real below, since we never vec_free(vam->inbuf); - */ - vec_validate (vam->inbuf, 0); -#endif + /* vec_validated in the init routine */ + _vec_len (vam->inbuf) = 0; - vec_reset_length (vam->inbuf); vam->input = &_input; while (((c = unformat_get_input (input)) != '\n') && (c != UNFORMAT_END_OF_INPUT)) vec_add1 (vam->inbuf, c); - /* Add 1 octet's worth of extra space in case there are no args... */ + /* Null-terminate the command */ vec_add1 (vam->inbuf, 0); - /*$$$$ reinstall macro evaluator */ + /* In case no args given */ + vec_add1 (vam->inbuf, 0); /* Split input into cmd + args */ this_cmd = cmdp = vam->inbuf; @@ -123,7 +118,7 @@ api_command_fn (vlib_main_t * vm, /* Advance past the command */ while (argsp < (this_cmd + vec_len (this_cmd))) { - if (*argsp != ' ' && *argsp != '\t' && *argsp != '\n' && argsp != 0) + if (*argsp != ' ' && *argsp != '\t' && *argsp != '\n' && *argsp != 0) { argsp++; } @@ -133,15 +128,19 @@ api_command_fn (vlib_main_t * vm, /* NULL terminate the command */ *argsp++ = 0; - while (argsp < (this_cmd + vec_len (this_cmd))) - { - if (*argsp == ' ' || *argsp == '\t' || *argsp == '\n') - { - argsp++; - } - else - break; - } + /* No arguments? Ensure that argsp points to a proper (empty) string */ + if (argsp == (this_cmd + vec_len (this_cmd) - 1)) + argsp[0] = 0; + else + while (argsp < (this_cmd + vec_len (this_cmd))) + { + if (*argsp == ' ' || *argsp == '\t' || *argsp == '\n') + { + argsp++; + } + else + break; + } /* Blank input line? */ if (*cmdp == 0) |