]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
parser_bison: error out on duplicated type/typeof/element keywords
authorFlorian Westphal <fw@strlen.de>
Tue, 19 Dec 2023 15:22:32 +0000 (16:22 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 22 Jan 2025 23:41:53 +0000 (00:41 +0100)
commit 6c04e5ceb95068bb459b07307ecc3629d97a2043 upstream.

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

index 2218f3cf85af99ecd479a9a13504cc2d3d680c5b..f3bf8aa65f4823a2c6e9838e6b7381172aad90fa 100644 (file)
@@ -1993,11 +1993,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;
@@ -2025,6 +2034,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;
                        }
@@ -2102,6 +2115,12 @@ map_block                :       /* empty */     { $$ = $<set>-1; }
                                                data_type_expr  COLON   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 |= EXPR_F_INTERVAL;
@@ -2113,8 +2132,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;
@@ -2124,8 +2148,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;
 
@@ -2136,6 +2165,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;