]> 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)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 13 Aug 2025 18:08:58 +0000 (20:08 +0200)
commit 845b8d7208077310e77560a64b698973fb047ef2 upstream.

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 72e1a0a9c513dc97c973f8294079c1d6ea4ddcb2..25c55ba9d6581c8e5a67dafe72f95022c8e52e9e 100644 (file)
@@ -471,7 +471,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
+       }
+}