]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
mnl: name is ignored when deleting a table
authorFlorian Westphal <fw@strlen.de>
Wed, 16 Jan 2019 12:54:13 +0000 (13:54 +0100)
committerFlorian Westphal <fw@strlen.de>
Fri, 18 Jan 2019 22:01:20 +0000 (23:01 +0100)
nlt is reallocated, leaking first allocation and also removing
the table name/handle that was set on nlt object.

Add a test case for this as well, the batch is supposed to fail
when trying to delete a non-existant table, rather than wiping
all tables in the same address family.

Fixes: 12c362e2214a0 ("mnl: remove alloc_nftnl_table()")
Reported-by: Mikhail Morfikov <mmorfikov@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
src/mnl.c
tests/shell/testcases/transactions/0003table_0

index c3d16774f71f6208f6c15416e34976d762569a8f..dde232c7e29c4046deccebea2ec28efabaf7bea9 100644 (file)
--- a/src/mnl.c
+++ b/src/mnl.c
@@ -664,10 +664,6 @@ int mnl_nft_table_del(struct netlink_ctx *ctx, const struct cmd *cmd)
                nftnl_table_set_u64(nlt, NFTNL_TABLE_HANDLE,
                                    cmd->handle.handle.id);
 
-       nlt = nftnl_table_alloc();
-       if (nlt == NULL)
-               memory_allocation_error();
-
        nlh = nftnl_nlmsg_build_hdr(nftnl_batch_buffer(ctx->batch),
                                    NFT_MSG_DELTABLE,
                                    cmd->handle.family,
index 6e508fc2a02c7dbbb85ea955512636d84507629d..6861eabab125694df47dd76ab9f260cc4ee701fd 100755 (executable)
@@ -11,3 +11,38 @@ if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
 fi
+
+KERNEL_RULESET="$($NFT list ruleset)"
+if [ "" != "$KERNEL_RULESET" ] ; then
+       DIFF="$(which diff)"
+       echo "Got a ruleset, but expected empty: "
+       echo "$KERNEL_RULESET"
+       exit 1
+fi
+
+RULESET="table ip x {
+}
+table ip y {
+}"
+
+$NFT -f - <<< "$RULESET"
+if [ $? -ne 0 ] ; then
+        echo "E: unable to load good ruleset" >&2
+        exit 1
+fi
+
+RULESETFAIL="flush ruleset
+create table ip nat
+create table inet filter
+create chain ip nat testchain
+delete table ip testtable"
+
+# testtable doesn't exist, batch expected to fail
+$NFT -f - <<< "$RULESETFAIL" && exit 2
+
+KERNEL_RULESET="$($NFT list ruleset)"
+if [ "$RULESET" != "$KERNEL_RULESET" ] ; then
+        DIFF="$(which diff)"
+        [ -x $DIFF ] && $DIFF -u <(echo "$RULESET") <(echo "$KERNEL_RULESET")
+        exit 1
+fi