]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
parser: recover from errors in any block
authorPatrick McHardy <kaber@trash.net>
Tue, 4 Feb 2014 08:09:27 +0000 (08:09 +0000)
committerPatrick McHardy <kaber@trash.net>
Tue, 4 Feb 2014 08:12:01 +0000 (08:12 +0000)
Move error recovery to the common_block definition to handle errors
in any block. Queue those errors and abort parsing once a threshold
is reached.

With this in place, we can continue parsing when errors occur and
show all of them to the user at once.

tests/error.1:3:8-8: Error: syntax error, unexpected '{', expecting string
filter {
       ^
tests/error.1:4:13-13: Error: syntax error, unexpected newline
filter input
            ^
tests/error.1:5:17-17: Error: syntax error, unexpected newline
filter input tcp
                ^
tests/error.1:6:23-23: Error: syntax error, unexpected newline
filter input tcp dport

Signed-off-by: Patrick McHardy <kaber@trash.net>
include/nftables.h
include/parser.h
src/main.c
src/parser.y

index 5a0008705fe1f31a79c0c98ee2e6f577af26da5d..7f3968d45cf2c8b434f7b229681d821e3c1e2622 100644 (file)
@@ -24,6 +24,7 @@ enum debug_level {
 
 #define INCLUDE_PATHS_MAX      16
 
+extern unsigned int max_errors;
 extern unsigned int numeric_output;
 extern unsigned int handle_output;
 extern unsigned int debug_level;
index f5dd6f4bb597ac4d2e7587068cf1af2761b98116..7a1c2dbe9fdcd64166be026237393690d4728f7c 100644 (file)
@@ -19,6 +19,7 @@ struct parser_state {
        unsigned int                    indesc_idx;
 
        struct list_head                *msgs;
+       unsigned int                    nerrs;
 
        struct scope                    top_scope;
        struct scope                    *scopes[SCOPE_NEST_MAX];
index 28ce1aa613955e38a3ba9fbe042643e32bc8f9fd..2320a826143897b48908dcdfa616ade1eb7fd880 100644 (file)
@@ -26,6 +26,7 @@
 #include <erec.h>
 #include <mnl.h>
 
+unsigned int max_errors = 10;
 unsigned int numeric_output;
 unsigned int handle_output;
 #ifdef DEBUG
@@ -219,7 +220,7 @@ int nft_run(void *scanner, struct parser_state *state, struct list_head *msgs)
        int ret = 0;
 
        ret = nft_parse(scanner, state);
-       if (ret != 0)
+       if (ret != 0 || state->nerrs > 0)
                return -1;
 
        memset(&ctx, 0, sizeof(ctx));
index fa33b570ef87975f6253786ede430094f4fac862..0dad036cf3026236cdde471a4b18e6ed5e91c0c8 100644 (file)
@@ -518,6 +518,12 @@ common_block               :       INCLUDE         QUOTED_STRING   stmt_seperator
                                symbol_bind(current_scope(state), $2, $4);
                                xfree($2);
                        }
+                       |       error           stmt_seperator
+                       {
+                               if (++state->nerrs == max_errors)
+                                       YYABORT;
+                               yyerrok;
+                       }
                        ;
 
 line                   :       common_block                    { $$ = NULL; }
@@ -542,7 +548,6 @@ line                        :       common_block                    { $$ = NULL; }
 
                                YYACCEPT;
                        }
-                       |       base_cmd        error           { $$ = $1; }
                        ;
 
 base_cmd               :       /* empty */     add_cmd         { $$ = $1; }