]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: reject attempt to update a set
authorFlorian Westphal <fw@strlen.de>
Mon, 4 Dec 2023 21:00:06 +0000 (22:00 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 12 Dec 2023 12:30:09 +0000 (13:30 +0100)
commit 5f43ea807bb0f5b30f332c2c96f13e33c9243d22 upstream.

This will crash as set->data is NULL, so check that SET_REF is pointing
to a map:

Error: candidates_ipv4 is not a map
tcp dport 10003 ip saddr . tcp dport @candidates_ipv4 add @candidates_ipv4 { ip saddr . 10 :0004 timeout 1s }
                                     ~~~~~~~~~~~~~~~~

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

index 777daa43cd94376507183d87eace738a504e70fc..639bc0127862a15f5545af68c3dac0ab1f138b1a 100644 (file)
@@ -4066,6 +4066,10 @@ static int stmt_evaluate_map(struct eval_ctx *ctx, struct stmt *stmt)
                return expr_error(ctx->msgs, stmt->map.set,
                                  "Expression does not refer to a set");
 
+       if (!set_is_map(stmt->map.set->set->flags))
+               return expr_error(ctx->msgs, stmt->map.set,
+                                 "%s is not a map", stmt->map.set->set->handle.set.name);
+
        if (stmt_evaluate_key(ctx, stmt,
                              stmt->map.set->set->key->dtype,
                              stmt->map.set->set->key->len,
diff --git a/tests/shell/testcases/bogons/nft-f/add_to_a_set_crash b/tests/shell/testcases/bogons/nft-f/add_to_a_set_crash
new file mode 100644 (file)
index 0000000..80a01b4
--- /dev/null
@@ -0,0 +1,11 @@
+table t {
+        set candidates_ipv4 {
+                type ipv4_addr . inet_service
+                size 65535
+                flags dynamic,timeout
+        }
+
+        chain input {
+                tcp dport 10003 ip saddr . tcp dport @candidates_ipv4 add @candidates_ipv4 { ip saddr . 10 :0004 timeout 1s }
+        }
+}