From 53d5ec367882becf01cf3c484f3570f10a11618d Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Thu, 15 Dec 2016 23:53:02 +0100 Subject: [PATCH] lib: parser: fix SEGV when Tab hits non-WORD_TKN If processing finds that there is only 1 candidate, but that candidate is not a WORD_TKN that we can tab-complete on, the status would remain at CMD_COMPLETE_FULL_MATCH, but the resulting list of possible completions is empty. This then SEGVs in lib/vty.c where it tries to access the first element of the list, assuming FULL_MATCH always has 1 element there... Signed-off-by: David Lamparter Cc: Quentin Young --- lib/command.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/command.c b/lib/command.c index 8d5493ca56..a93f3a55e8 100644 --- a/lib/command.c +++ b/lib/command.c @@ -686,6 +686,19 @@ cmd_complete_command (vector vline, struct vty *vty, int *status) } vector_free (initial_comps); + // since we filtered results, we need to re-set status code + switch (vector_active (comps)) + { + case 0: + *status = CMD_ERR_NO_MATCH; + break; + case 1: + *status = CMD_COMPLETE_FULL_MATCH; + break; + default: + *status = CMD_COMPLETE_LIST_MATCH; + } + // copy completions text into an array of char* ret = XMALLOC (MTYPE_TMP, (vector_active (comps)+1) * sizeof (char *)); unsigned int i; -- 2.39.5