]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: error out if basetypes are different
authorFlorian Westphal <fw@strlen.de>
Mon, 4 Dec 2023 17:30:51 +0000 (18:30 +0100)
committerFlorian Westphal <fw@strlen.de>
Tue, 5 Dec 2023 11:43:21 +0000 (12:43 +0100)
prefer
binop_with_different_basetype_assert:3:29-35: Error: Binary operation (<<) with different base types (string vs integer) is not supported
oifname set ip9dscp << 26 | 0x10
            ^^^^^^^~~~~~~
to assertion failure.

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

index b6670254b9fd9e06ea0096c31c7af22cb667477f..51ae276aac6ac1cd1d1e47ab7744542025313196 100644 (file)
@@ -1451,8 +1451,11 @@ static int expr_evaluate_binop(struct eval_ctx *ctx, struct expr **expr)
                                         "for %s expressions",
                                         sym, expr_name(right));
 
-       /* The grammar guarantees this */
-       assert(datatype_equal(expr_basetype(left), expr_basetype(right)));
+       if (!datatype_equal(expr_basetype(left), expr_basetype(right)))
+               return expr_binary_error(ctx->msgs, left, op,
+                                        "Binary operation (%s) with different base types "
+                                        "(%s vs %s) is not supported",
+                                        sym, expr_basetype(left)->name, expr_basetype(right)->name);
 
        switch (op->op) {
        case OP_LSHIFT:
diff --git a/tests/shell/testcases/bogons/nft-f/binop_with_different_basetype_assert b/tests/shell/testcases/bogons/nft-f/binop_with_different_basetype_assert
new file mode 100644 (file)
index 0000000..e843600
--- /dev/null
@@ -0,0 +1,5 @@
+table ip t {
+        chain c {
+                oifname set ip9dscp << 26 | 0x10
+        }
+}