]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xtables: Fix potential segfault in nft_rule_append()
authorPhil Sutter <phil@nwl.cc>
Mon, 6 Aug 2018 15:23:23 +0000 (17:23 +0200)
committerFlorian Westphal <fw@strlen.de>
Mon, 6 Aug 2018 16:17:39 +0000 (18:17 +0200)
If batch_rule_add() failed (ENOMEM), nft_rule_append() frees the
rule and then tries to add it to the rule cache. Better return 0
(failure) instead of continuing.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
iptables/nft.c

index b893859d286607dc9fa3e21d67271ca2a2e84a5f..1c076510962b3f4e40dd459d8907c6c1f0e38749 100644 (file)
@@ -1173,8 +1173,10 @@ nft_rule_append(struct nft_handle *h, const char *chain, const char *table,
        } else
                type = NFT_COMPAT_RULE_APPEND;
 
-       if (batch_rule_add(h, type, r) < 0)
+       if (batch_rule_add(h, type, r) < 0) {
                nftnl_rule_free(r);
+               return 0;
+       }
 
        if (verbose)
                h->ops->print_rule(r, 0, FMT_PRINT_RULE);