]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
scanner: don't bug on too large values
authorPablo Neira Ayuso <pablo@netfilter.org>
Sun, 30 Nov 2014 21:52:20 +0000 (22:52 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 1 Dec 2014 16:28:25 +0000 (17:28 +0100)
Add a new ERROR symbol to handle scanning of too large values.

 <cmdline>:1:36-99: Error: bad value '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
 add rule ip test-ip4 input ct mark 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
instead of:

 BUG: nft: scanner.l:470: nft_lex: Assertion `0' failed.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/parser_bison.y
src/scanner.l

index ad2951a191be1d0ba61caf869235034496a9554d..6c7a036a1a15a2ddad8b40e888098e27d8b7c89a 100644 (file)
@@ -209,7 +209,8 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 %token <val> NUM               "number"
 %token <string> STRING         "string"
 %token <string> QUOTED_STRING
-%destructor { xfree($$); }     STRING QUOTED_STRING
+%token <string> ERROR          "error"
+%destructor { xfree($$); }     STRING QUOTED_STRING ERROR
 
 %token LL_HDR                  "ll"
 %token NETWORK_HDR             "nh"
@@ -465,6 +466,8 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 %destructor { expr_free($$); } list_expr
 %type <expr>                   concat_expr map_lhs_expr
 %destructor { expr_free($$); } concat_expr map_lhs_expr
+%type <expr>                   error_expr
+%destructor { expr_free($$); } error_expr
 
 %type <expr>                   map_expr
 %destructor { expr_free($$); } map_expr
@@ -1668,6 +1671,16 @@ expr                     :       concat_expr
                        |       set_expr
                        |       map_expr
                        |       multiton_expr
+                       |       error_expr
+                       ;
+
+error_expr             :       ERROR
+                       {
+                               $$ = NULL;
+                               erec_queue(error(&@1, "bad value '%s'", $1),
+                                          state->msgs);
+                               YYERROR;
+                       }
                        ;
 
 set_expr               :       '{'     set_list_expr           '}'
index 2fafa71ae84f84c7779d813920c788ecd9be91c9..72b544714714408f7122a3869d5065d1f814bb25 100644 (file)
@@ -459,16 +459,20 @@ addrstring        ({macaddr}|{ip4addr}|{ip6addr})
 {decstring}            {
                                errno = 0;
                                yylval->val = strtoull(yytext, NULL, 0);
-                               if (errno != 0)
-                                       BUG();
+                               if (errno != 0) {
+                                       yylval->string = xstrdup(yytext);
+                                       return ERROR;
+                               }
                                return NUM;
                        }
 
 {hexstring}            {
                                errno = 0;
                                yylval->val = strtoull(yytext, NULL, 0);
-                               if (errno != 0)
-                                       BUG();
+                               if (errno != 0) {
+                                       yylval->string = xstrdup(yytext);
+                                       return ERROR;
+                               }
                                return NUM;
                        }