]> 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)
committerFlorian Westphal <fw@strlen.de>
Tue, 19 Dec 2023 16:32:43 +0000 (17:32 +0100)
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 7082d2ba00a01aee199bdc912708112c5e27e441..c948447d28e8a8335791db9eea89bfc70421c91e 100644 (file)
@@ -2152,11 +2152,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;
@@ -2184,6 +2193,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;
                        }
@@ -2255,6 +2268,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;
@@ -2266,8 +2285,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;
@@ -2277,8 +2301,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;
 
@@ -2289,6 +2318,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;