]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: disable meta set with ranges
authorFlorian Westphal <fw@strlen.de>
Mon, 4 Dec 2023 18:04:58 +0000 (19:04 +0100)
committerFlorian Westphal <fw@strlen.de>
Tue, 5 Dec 2023 11:43:21 +0000 (12:43 +0100)
... this will cause an assertion in netlink linearization, catch this
at eval stage instead.

before:
BUG: unknown expression type range
nft: netlink_linearize.c:908: netlink_gen_expr: Assertion `0' failed.

after:
/unknown_expr_type_range_assert:3:31-40: Error: Meta expression cannot be a range
meta mark set 0x001-3434
              ^^^^^^^^^^

Signed-off-by: Florian Westphal <fw@strlen.de>
src/evaluate.c
tests/shell/testcases/bogons/nft-f/unknown_expr_type_range_assert [new file with mode: 0644]

index 51ae276aac6ac1cd1d1e47ab7744542025313196..131b0a0eaa66b3e19e4d68581ceb499dbab44c0c 100644 (file)
@@ -3169,6 +3169,19 @@ static int stmt_evaluate_meta(struct eval_ctx *ctx, struct stmt *stmt)
                                &stmt->meta.expr);
        ctx->stmt_len = 0;
 
+       if (ret < 0)
+               return ret;
+
+       switch (stmt->meta.expr->etype) {
+       case EXPR_RANGE:
+               ret = expr_error(ctx->msgs, stmt->meta.expr,
+                                "Meta expression cannot be a range");
+               break;
+       default:
+               break;
+
+       }
+
        return ret;
 }
 
diff --git a/tests/shell/testcases/bogons/nft-f/unknown_expr_type_range_assert b/tests/shell/testcases/bogons/nft-f/unknown_expr_type_range_assert
new file mode 100644 (file)
index 0000000..234dd62
--- /dev/null
@@ -0,0 +1,5 @@
+table ip x {
+        chain k {
+                meta mark set 0x001-3434
+        }
+}