]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: Fix segfault on erroneous command
authorQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 31 Oct 2016 03:34:27 +0000 (03:34 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 31 Oct 2016 03:34:27 +0000 (03:34 +0000)
Command completion vector should only be copied if it is
non-null.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/command.c

index a12591a8bcf0ab1aa96407742d128d8b4dfd38d3..5e493a1c01c0f8677bc970b98fbbe15e5ab74871 100644 (file)
@@ -677,20 +677,21 @@ cmd_complete_command (vector vline, struct vty *vty, int *status)
   vector comps, initial_comps;
   initial_comps = cmd_complete_command_real (input_line, vty, status);
 
-  // filter out everything that is not suitable for a tab-completion
-  comps = vector_init (VECTOR_MIN_SIZE);
-  for (unsigned int i = 0; i < vector_active(initial_comps); i++)
-  {
-    struct cmd_token *token = vector_slot (initial_comps, i);
-    if (token->type == WORD_TKN)
-      vector_set (comps, token);
-    else
-      del_cmd_token (token);
-  }
-  vector_free (initial_comps);
-
   if (!MATCHER_ERROR (*status))
   {
+    assert (initial_comps);
+    // filter out everything that is not suitable for a tab-completion
+    comps = vector_init (VECTOR_MIN_SIZE);
+    for (unsigned int i = 0; i < vector_active(initial_comps); i++)
+    {
+      struct cmd_token *token = vector_slot (initial_comps, i);
+      if (token->type == WORD_TKN)
+        vector_set (comps, token);
+      else
+        del_cmd_token (token);
+    }
+    vector_free (initial_comps);
+
     // copy completions text into an array of char*
     ret = XMALLOC (MTYPE_TMP, vector_active (comps) * sizeof (char *) + 1);
     unsigned int i;