]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: Fix various minor bugs
authorQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 9 Aug 2016 17:37:01 +0000 (17:37 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 9 Aug 2016 17:37:01 +0000 (17:37 +0000)
- cmd_make_strvec returns null pointer if str
  begins with a '#'
- disallow options nested options
- NULL out state variable in parser
- flip backwards comparison
- fix memory leak in lexer

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/command_lex.l
lib/command_match.c
lib/command_parse.y
lib/grammar_sandbox.c

index 920c03db8ebedc827e5b1c0bb75a73b16a319e75..b3276894f559efdb92b1bc138e4a38a5831e1c72 100644 (file)
@@ -25,7 +25,9 @@
 %{
 #include "command_parse.h"
 
-extern void set_buffer_string(const char *);
+extern void set_lexer_string (const char *);
+extern void cleanup_lexer (void);
+YY_BUFFER_STATE buffer;
 %}
 
 WORD            (\-|\+)?[a-z\*][-+_a-zA-Z0-9\*]*
@@ -62,7 +64,13 @@ RANGE           \({NUMBER}[ ]?\-[ ]?{NUMBER}\)
 %%
 
 void
-set_buffer_string(const char *string)
+set_lexer_string (const char *string)
 {
-  yy_scan_string(string);
+  buffer = yy_scan_string (XSTRDUP(MTYPE_TMP, string));
+}
+
+void
+cleanup_lexer ()
+{
+  yy_delete_buffer (buffer);
 }
index 011ac698cbb8c0cafb5b026d9124f0748de2fc53..9b9f8a0ec5f9d58b42e6b699287e284181579128 100644 (file)
@@ -158,6 +158,8 @@ match_command (struct graph_node *start,
 static struct list *
 match_command_r (struct graph_node *start, vector vline, unsigned int n)
 {
+  assert (n < vector_active (vline));
+
   // get the minimum match level that can count as a full match
   enum match_type minmatch = min_match_level (start->type);
 
index 6b972afe9049151dbcf3fa205c75f3816a5d696a..51c2331dc7987aa998433a27f2e490e272a26d72 100644 (file)
   yylex (void);
 
   extern void
-  set_buffer_string (const char *);
+  set_lexer_string (const char *);
+
+  extern void
+  cleanup_lexer (void);
 }
 
 /* functionality this unit exports */
   optnode_start = optnode_end = NULL;
 
   /* set string to parse */
-  set_buffer_string (element->string);
+  set_lexer_string (element->string);
 
   /* copy docstring and keep a pointer to the copy */
   docstr = element->doc ? XSTRDUP(MTYPE_TMP, element->doc) : NULL;
@@ -341,7 +344,6 @@ selector_element_root:
 
 selector_token:
   selector_element_root
-| option
 ;
 
 /* [option|set] productions */
@@ -368,6 +370,7 @@ option_element:
 
   add_node (optnode_start, seqhead);
   add_node ($1, optnode_end);
+  seqhead = NULL;
 }
 
 option_token_seq:
@@ -412,6 +415,9 @@ cleanup()
   /* free resources */
   free (docstr_start);
 
+  /* cleanup lexer */
+  cleanup_lexer();
+
   /* clear state pointers */
   seqhead = NULL;
   currnode = NULL;
index 39d4d6b7cd6cc99640383ed57aaddfaed2d7f6c5..cf9ce2bb58fd92f10aaedaa439d52c58bae4a9d0 100644 (file)
@@ -63,7 +63,7 @@ DEFUN (grammar_test,
 
   // initialize a pretend cmd_element
   struct cmd_element *cmd = XCALLOC(MTYPE_CMD_TOKENS, sizeof(struct cmd_element));
-  cmd->string = command;
+  cmd->string = XSTRDUP(MTYPE_TMP, command);
   cmd->doc = NULL;
   cmd->func = NULL;
   cmd->tokens = vector_init(VECTOR_MIN_SIZE);
@@ -132,6 +132,9 @@ DEFUN (grammar_test_match,
        "command to match")
 {
   char *cmdstr = argv_concat(argv, argc, 0);
+  if (cmdstr[0] == '#')
+    return CMD_SUCCESS;
+
   vector command = cmd_make_strvec (cmdstr);
 
   struct list *argvv = NULL;
@@ -145,7 +148,7 @@ DEFUN (grammar_test_match,
       struct listnode *ln;
       struct graph_node *gn;
       for (ALL_LIST_ELEMENTS_RO(argvv,ln,gn))
-        if (gn->type != END_GN)
+        if (gn->type == END_GN)
           zlog_info ("func: %p", gn->element->func);
         else
           zlog_info ("%s -- %s", gn->text, gn->arg);