]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: parser: fix SEGV when Tab hits non-WORD_TKN
authorDavid Lamparter <equinox@opensourcerouting.org>
Thu, 15 Dec 2016 22:53:02 +0000 (23:53 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Fri, 16 Dec 2016 19:42:01 +0000 (20:42 +0100)
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>
lib/command.c

index 8d5493ca56ac1aa1d99507d093822b8958caa00a..a93f3a55e802bb5ce0cb1311cd1b90910ce8db6d 100644 (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;