summaryrefslogtreecommitdiffstats
path: root/src/parser_bison.y
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2023-12-19 16:22:32 +0100
committerFlorian Westphal <fw@strlen.de>2023-12-19 17:32:43 +0100
commit6c04e5ceb95068bb459b07307ecc3629d97a2043 (patch)
tree5646e38880542055783862f2fefd77d43d77876f /src/parser_bison.y
parent84da729e067a68bd50be8c0791d16901360be5ad (diff)
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 <fw@strlen.de>
Diffstat (limited to 'src/parser_bison.y')
-rw-r--r--src/parser_bison.y38
1 files changed, 36 insertions, 2 deletions
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 */ { $$ = $<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;