lib: parser: fix SEGV when Tab hits non-WORD_TKN

If <Tab> 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 <equinox@opensourcerouting.org>
Cc: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
David Lamparter 2016-12-15 23:53:02 +01:00
parent 7d5718c140
commit 53d5ec3678

View File

@ -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;