]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests: shell: cover refcount leak of mapping rhs
authorPablo Neira Ayuso <pablo@netfilter.org>
Tue, 27 Jun 2023 12:12:53 +0000 (14:12 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 27 Jun 2023 12:15:11 +0000 (14:15 +0200)
Add a test to cover reference count leak in maps by adding twice
same element, then flush.

Reported-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
tests/shell/testcases/maps/0016map_leak_0 [new file with mode: 0755]

diff --git a/tests/shell/testcases/maps/0016map_leak_0 b/tests/shell/testcases/maps/0016map_leak_0
new file mode 100755 (executable)
index 0000000..e110ee4
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+set -e
+
+RULESET="table ip t {
+        map sourcemap {
+                type ipv4_addr : verdict
+                elements = { 100.123.10.2 : jump c }
+        }
+
+        chain c {
+        }
+}"
+
+$NFT -f - <<< "$RULESET"
+# again, since it is addition, not creation, it is successful
+$NFT -f - <<< "$RULESET"
+# flush it to check for refcount leak
+$NFT flush ruleset
+
+#
+# again with stateful objects
+#
+
+RULESET="table ip t {
+       counter c {}
+
+        map sourcemap {
+                type ipv4_addr : counter
+                elements = { 100.123.10.2 : \"c\" }
+        }
+}"
+
+$NFT -f - <<< "$RULESET"
+# again, since it is addition, not creation, it is successful
+$NFT -f - <<< "$RULESET"
+# flush it to check for refcount leak
+$NFT flush ruleset