]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
parser: close scope when encountering an error in a table or chain 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)
Close the scopes when destroying a table_block/chain_block. Also add
assertions to open_scope()/close_scope() to catch memory corruption
early.

Signed-off-by: Patrick McHardy <kaber@trash.net>
src/parser.y

index 24f022a56d7b7e7383f879a3124677a3b211530e..fa33b570ef87975f6253786ede430094f4fac862 100644 (file)
@@ -52,12 +52,14 @@ static struct scope *current_scope(const struct parser_state *state)
 
 static void open_scope(struct parser_state *state, struct scope *scope)
 {
+       assert(state->scope < array_size(state->scopes) - 1);
        scope_init(scope, current_scope(state));
        state->scopes[++state->scope] = scope;
 }
 
 static void close_scope(struct parser_state *state)
 {
+       assert(state->scope > 0);
        state->scope--;
 }
 
@@ -367,9 +369,9 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 %type <val>                    handle_spec family_spec position_spec
 
 %type <table>                  table_block_alloc table_block
-%destructor { table_free($$); }        table_block_alloc
+%destructor { close_scope(state); table_free($$); }    table_block_alloc
 %type <chain>                  chain_block_alloc chain_block
-%destructor { chain_free($$); }        chain_block_alloc
+%destructor { close_scope(state); chain_free($$); }    chain_block_alloc
 %type <rule>                   rule
 %destructor { rule_free($$); } rule