summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2025-03-16 22:39:10 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2025-07-27 20:23:37 +0200
commitdf54222b7ca053f4464eb2a724504fc2c3a5e50e (patch)
tree83fa42e681121ecd4a82896291f8c1ea59b71b89
parent1363a48ad440d563cc3862b335d8e7efec2d1a1d (diff)
parser_bison: reject non-serializeable typeof expressions
commit a1bb1814148c5011d50cb566a92b3b30fff118b0 upstream. Included bogon asserts with: BUG: unhandled key type 13 nft: src/intervals.c:73: setelem_expr_to_range: Assertion `0' failed. This should be rejected at parser stage, but the check for udata support was only done on the first item in a concatenation. After fix, parser rejects this with: Error: primary expression type 'symbol' lacks typeof serialization Fixes: 6e48df5329ea ("src: add "typeof" build/parse/print support") Signed-off-by: Florian Westphal <fw@strlen.de>
-rw-r--r--src/parser_bison.y14
-rw-r--r--tests/shell/testcases/bogons/nft-f/typeof_map_with_plain_integer_assert7
2 files changed, 17 insertions, 4 deletions
diff --git a/src/parser_bison.y b/src/parser_bison.y
index 30a4c1ed..67ac8f57 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -798,8 +798,8 @@ int nft_lex(void *, void *, void *);
%type <expr> symbol_expr verdict_expr integer_expr variable_expr chain_expr policy_expr
%destructor { expr_free($$); } symbol_expr verdict_expr integer_expr variable_expr chain_expr policy_expr
-%type <expr> primary_expr shift_expr and_expr typeof_expr typeof_data_expr typeof_key_expr typeof_verdict_expr
-%destructor { expr_free($$); } primary_expr shift_expr and_expr typeof_expr typeof_data_expr typeof_key_expr typeof_verdict_expr
+%type <expr> primary_expr shift_expr and_expr primary_typeof_expr typeof_expr typeof_data_expr typeof_key_expr typeof_verdict_expr
+%destructor { expr_free($$); } primary_expr shift_expr and_expr primary_typeof_expr typeof_expr typeof_data_expr typeof_key_expr typeof_verdict_expr
%type <expr> exclusive_or_expr inclusive_or_expr
%destructor { expr_free($$); } exclusive_or_expr inclusive_or_expr
%type <expr> basic_expr
@@ -1999,7 +1999,7 @@ typeof_data_expr : INTERVAL typeof_expr
}
;
-typeof_expr : primary_expr
+primary_typeof_expr : primary_expr
{
if (expr_ops($1)->build_udata == NULL) {
erec_queue(error(&@1, "primary expression type '%s' lacks typeof serialization", expr_ops($1)->name),
@@ -2010,7 +2010,13 @@ typeof_expr : primary_expr
$$ = $1;
}
- | typeof_expr DOT primary_expr
+ ;
+
+typeof_expr : primary_typeof_expr
+ {
+ $$ = $1;
+ }
+ | typeof_expr DOT primary_typeof_expr
{
struct location rhs[] = {
[1] = @2,
diff --git a/tests/shell/testcases/bogons/nft-f/typeof_map_with_plain_integer_assert b/tests/shell/testcases/bogons/nft-f/typeof_map_with_plain_integer_assert
new file mode 100644
index 00000000..f1dc12f6
--- /dev/null
+++ b/tests/shell/testcases/bogons/nft-f/typeof_map_with_plain_integer_assert
@@ -0,0 +1,7 @@
+table ip t {
+ map m {
+ typeof ip saddr . meta mark . 0: verdict
+ flags interval
+ elements = { 127.0.0.1-127.0.0.4 . 0x00123434-0x00b00122 : accept }
+ }
+}