Linux Netfilter development
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nft] parser_bison: error out on duplicated type/typeof/element keywords
Date: Tue, 19 Dec 2023 16:22:32 +0100	[thread overview]
Message-ID: <20231219152235.13511-1-fw@strlen.de> (raw)

Otherwise nft will leak the previous definition (expressions).
Also remove the nonsensical

   datatype_set($1->key, $3->dtype);

This is a no-op, at this point: $1->key and $3 are identical.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 src/parser_bison.y | 38 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/src/parser_bison.y b/src/parser_bison.y
index 8f4182c9b296..86fb9f077db8 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -2174,11 +2174,20 @@ set_block		:	/* empty */	{ $$ = $<set>-1; }
 			|	set_block	stmt_separator
 			|	set_block	TYPE		data_type_expr	stmt_separator	close_scope_type
 			{
+				if (already_set($1->key, &@2, state)) {
+					expr_free($3);
+					YYERROR;
+				}
+
 				$1->key = $3;
 				$$ = $1;
 			}
 			|	set_block	TYPEOF		typeof_expr	stmt_separator
 			{
+				if (already_set($1->key, &@2, state)) {
+					expr_free($3);
+					YYERROR;
+				}
 				$1->key = $3;
 				datatype_set($1->key, $3->dtype);
 				$$ = $1;
@@ -2206,6 +2215,10 @@ set_block		:	/* empty */	{ $$ = $<set>-1; }
 			}
 			|	set_block	ELEMENTS	'='		set_block_expr
 			{
+				if (already_set($1->init, &@2, state)) {
+					expr_free($4);
+					YYERROR;
+				}
 				$1->init = $4;
 				$$ = $1;
 			}
@@ -2277,6 +2290,12 @@ map_block		:	/* empty */	{ $$ = $<set>-1; }
 						data_type_expr	COLON	map_block_data_interval data_type_expr
 						stmt_separator	close_scope_type
 			{
+				if (already_set($1->key, &@2, state)) {
+					expr_free($3);
+					expr_free($6);
+					YYERROR;
+				}
+
 				$1->key = $3;
 				$1->data = $6;
 				$1->data->flags |= $5;
@@ -2288,8 +2307,13 @@ map_block		:	/* empty */	{ $$ = $<set>-1; }
 						typeof_expr	COLON	typeof_data_expr
 						stmt_separator
 			{
+				if (already_set($1->key, &@2, state)) {
+					expr_free($3);
+					expr_free($5);
+					YYERROR;
+				}
+
 				$1->key = $3;
-				datatype_set($1->key, $3->dtype);
 				$1->data = $5;
 
 				$1->flags |= NFT_SET_MAP;
@@ -2299,8 +2323,13 @@ map_block		:	/* empty */	{ $$ = $<set>-1; }
 						typeof_expr	COLON	INTERVAL	typeof_expr
 						stmt_separator
 			{
+				if (already_set($1->key, &@2, state)) {
+					expr_free($3);
+					expr_free($6);
+					YYERROR;
+				}
+
 				$1->key = $3;
-				datatype_set($1->key, $3->dtype);
 				$1->data = $6;
 				$1->data->flags |= EXPR_F_INTERVAL;
 
@@ -2311,6 +2340,11 @@ map_block		:	/* empty */	{ $$ = $<set>-1; }
 						data_type_expr	COLON	map_block_obj_type
 						stmt_separator	close_scope_type
 			{
+				if (already_set($1->key, &@2, state)) {
+					expr_free($3);
+					YYERROR;
+				}
+
 				$1->key = $3;
 				$1->objtype = $5;
 				$1->flags  |= NFT_SET_OBJECT;
-- 
2.41.0


                 reply	other threads:[~2023-12-19 15:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20231219152235.13511-1-fw@strlen.de \
    --to=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.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