From 6c04e5ceb95068bb459b07307ecc3629d97a2043 Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Tue, 19 Dec 2023 16:22:32 +0100 Subject: parser_bison: error out on duplicated type/typeof/element keywords 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 --- src/parser_bison.y | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'src/parser_bison.y') diff --git a/src/parser_bison.y b/src/parser_bison.y index 7082d2ba..c948447d 100644 --- a/src/parser_bison.y +++ b/src/parser_bison.y @@ -2152,11 +2152,20 @@ set_block : /* empty */ { $$ = $-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 */ { $$ = $-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 */ { $$ = $-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 */ { $$ = $-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 */ { $$ = $-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 */ { $$ = $-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; -- cgit v1.2.3