There are a number of bugs in parsing zero argument commands in CLI
Issuing "configure policer" command without arguments cause SIGSEGV
Thread 1 "vpp_main" received signal SIGSEGV, Segmentation fault. strlen () at ../sysdeps/x86_64/strlen.S:106
Issuing "trace add" in release configuration without arguments cause
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:58 #1 0x00007fbc3fb1c37a in __GI_abort () at abort.c:89 #2 0x0000559d14686473 in os_panic () at /home/user/vpp/build-data/../src/vpp/vnet/main.c:263 #3 0x00007fbc40338e8d in clib_mem_alloc_aligned_at_offset (os_out_of_memory_on_failure=1, align_offset=4, align=4, size=8616811756) at /home/user/vpp/build-data/../src/vppinfra/mem.h:102 #4 vec_resize_allocate_memory (v=<optimized out>, length_increment=1077101469, data_bytes=8616811756, header_bytes=<optimized out>, header_bytes@entry=0, data_align=data_align@entry=4) at /home/user/vpp/build-data/../src/vppinfra/vec.c:59
And so on
The problem is in the unformat checker
uword
unformat_line_input (unformat_input_t * i, va_list * va)
{
unformat_input_t *result = va_arg (*va, unformat_input_t *);
u8 *line;
unformat_user (i, unformat_line, &line));
unformat_init_vector (result, line);
return 1;
}
which always return 1 even if there are no symbols in the input line, just "\n"
Proposed patch is something like that
diff --git a/src/vppinfra/unformat.c b/src/vppinfra/unformat.c index f626f05e..5b17562f 100644 --- a/src/vppinfra/unformat.c +++ b/src/vppinfra/unformat.c @@ -401,7 +401,7 @@ unformat_line (unformat_input_t * i, va_list * va) } *result = line; - return 1; + return vec_len (line); } /* Parse a line ending with \n and return it as an unformat_input_t. */ @@ -410,7 +410,8 @@ unformat_line_input (unformat_input_t * i, va_list * va) { unformat_input_t *result = va_arg (*va, unformat_input_t *); u8 *line; - unformat_user (i, unformat_line, &line); + if (!unformat_user (i, unformat_line, &line)) + return 0; unformat_init_vector (result, line); return 1; }