]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: don't BUG on unexpected base datatype
authorFlorian Westphal <fw@strlen.de>
Fri, 13 Jun 2025 14:46:06 +0000 (16:46 +0200)
committerFlorian Westphal <fw@strlen.de>
Wed, 18 Jun 2025 22:49:57 +0000 (00:49 +0200)
Included bogon will cause a crash but this is the evaluation stage where
we can just emit an error instead.

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

index 9c7f23cb080efc3c7ea882ab9e546ccbcff1d5c6..872a9e0d8c61cff4c391ed7f6f127a05e1363182 100644 (file)
@@ -482,7 +482,8 @@ static int expr_evaluate_value(struct eval_ctx *ctx, struct expr **expr)
                        return -1;
                break;
        default:
-               BUG("invalid basetype %s\n", expr_basetype(*expr)->name);
+               return expr_error(ctx->msgs, *expr, "Unexpected datatype %s",
+                                 (*expr)->dtype->name);
        }
        return 0;
 }
diff --git a/tests/shell/testcases/bogons/nft-f/invalid_basetype_verdict_assert b/tests/shell/testcases/bogons/nft-f/invalid_basetype_verdict_assert
new file mode 100644 (file)
index 0000000..f85ce7f
--- /dev/null
@@ -0,0 +1,11 @@
+table ip t {
+       map m {
+               type ipv4_addr . inet_service : ipv4_addr .  verdict
+               elements = { 10.0.0.1 . 42 : 10.1.1.1 . 0 }
+       }
+
+       chain c {
+               type nat hook prerouting priority dstnat; policy accept;
+               dnat ip to ip saddr . tcp dport map @m
+       }
+}