summaryrefslogtreecommitdiffstats
path: root/src/vlib
diff options
context:
space:
mode:
authorFan Zhang <roy.fan.zhang@intel.com>2020-03-12 09:26:38 +0000
committerPaul Vinciguerra <pvinci@vinciconsulting.com>2020-03-12 12:51:00 +0000
commitce266ad574c4145e837c716c46ef0ef6b02620ce (patch)
tree13a1c98bca8afae3cf423d55b64fba72cf21b65b /src/vlib
parentcd01fb4237b78a1805e1dd4b018bd03eb342580c (diff)
vlib: fix unix cli SIGSEGV for empty line input
When logging is enabled, an empty line input (press Enter only) will cause SIGSEGV. This patch fixes the problem by checking the command length first. Type: fix Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com> Change-Id: Ib4cbd1c7bfd6a694e289d28958875c7d2356a93e
Diffstat (limited to 'src/vlib')
-rw-r--r--src/vlib/unix/cli.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/vlib/unix/cli.c b/src/vlib/unix/cli.c
index 6e566d11ffd..2a13c84b92d 100644
--- a/src/vlib/unix/cli.c
+++ b/src/vlib/unix/cli.c
@@ -2557,7 +2557,8 @@ more:
format_timeval, 0 /* current bat-time */ ,
0 /* current bat-format */ ,
cli_file_index, cf->current_command);
- if (cf->current_command[vec_len (cf->current_command) - 1] != '\n')
+ if ((vec_len (cf->current_command) > 0) &&
+ (cf->current_command[vec_len (cf->current_command) - 1] != '\n'))
lv = format (lv, "\n");
int rv __attribute__ ((unused)) = write (um->log_fd, lv, vec_len (lv));
}