vlib: exec cmd handle scripts with blank lines 73/32273/2
authorDave Barach <dave@barachs.net>
Mon, 10 May 2021 23:01:42 +0000 (19:01 -0400)
committerFlorin Coras <florin.coras@gmail.com>
Tue, 11 May 2021 00:45:33 +0000 (00:45 +0000)
Type: fix
Fixes: 2f96e7648b9b7d501088eddff7e4a761973e71f4

Signed-off-by: Dave Barach <dave@barachs.net>
Change-Id: Ia75c863850c0df978f61bfc0343a167d8636ed97

src/vlib/unix/cli.c

index 7b9a231..c8ebb33 100644 (file)
@@ -3436,10 +3436,28 @@ unix_cli_exec (vlib_main_t * vm,
       vec_free (expanded);
     }
 
-  while (unformat_user (&sub_input, unformat_line_input, line_input))
+  while (1)
     {
-      vlib_cli_input (vm, line_input, 0, 0);
-      unformat_free (line_input);
+      int rv = unformat_user (&sub_input, unformat_line_input, line_input);
+
+      /* No match? */
+      if (rv == 0)
+       {
+         /* Out of input, we're done... */
+         if (sub_input.index == UNFORMAT_END_OF_INPUT)
+           {
+             unformat_free (line_input);
+             break;
+           }
+         /* Blank line... */
+         sub_input.index++;
+       }
+      else
+       {
+         /* Process the line we just read */
+         vlib_cli_input (vm, line_input, 0, 0);
+         unformat_free (line_input);
+       }
     }
   unformat_free (&sub_input);