netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH 5/8] parser: close scope when encountering an error in a table or chain block
Date: Tue,  4 Feb 2014 08:35:17 +0000	[thread overview]
Message-ID: <1391502920-19186-6-git-send-email-kaber@trash.net> (raw)
In-Reply-To: <1391502920-19186-1-git-send-email-kaber@trash.net>

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 | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/parser.y b/src/parser.y
index 24f022a..fa33b57 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -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
 
-- 
1.8.5.3


  parent reply	other threads:[~2014-02-04  8:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-04  8:35 [PATCH 0/8] nftables: fix and improve error reporting Patrick McHardy
2014-02-04  8:35 ` [PATCH 1/8] evaluate: determine implicit relational op before RHS constant checks Patrick McHardy
2014-02-04  8:35 ` [PATCH 2/8] scanner: don't update location's line_offset for newlines Patrick McHardy
2014-02-04  8:35 ` [PATCH 3/8] scanner: update last_line in struct location Patrick McHardy
2014-02-04  8:35 ` [PATCH 4/8] erec: skip includes with INDESC_INTERNAL Patrick McHardy
2014-02-04  8:35 ` Patrick McHardy [this message]
2014-02-04  8:35 ` [PATCH 6/8] parser: recover from errors in any block Patrick McHardy
2014-02-04  8:35 ` [PATCH 7/8] parser: evaluate commands immediately after parsing Patrick McHardy
2014-02-04  8:35 ` [PATCH 8/8] tests: add two tests for error reporting Patrick McHardy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1391502920-19186-6-git-send-email-kaber@trash.net \
    --to=kaber@trash.net \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).