Skip to contentSkip to conversation

xtables: Don't leak iter in error path of __nft_chain_zero_counters()

PATCH Applied Phil Sutter 2 participants 2 messages May 13, 2019 – May 15, 2019 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 xtables: Don't leak iter in error path of __nft_chain_zero_counters()

If batch_rule_add() fails, this function leaked the rule iterator object.

Fixes 4c54c892443c2 ("xtables: Catch errors when zeroing rule rounters")
---
 iptables/nft.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
iptables/nft.c +3 -1
index 6354b7e8e72fe..dab1db59ec971 100644
@@ -3374,8 +3374,10 @@ static int __nft_chain_zero_counters(struct nftnl_chain *c, void *data)
 			 * rule based on its handle only.
 			 */
 			nftnl_rule_unset(r, NFTNL_RULE_POSITION);
-			if (!batch_rule_add(h, NFT_COMPAT_RULE_REPLACE, r))
+			if (!batch_rule_add(h, NFT_COMPAT_RULE_REPLACE, r)) {
+				nftnl_rule_iter_destroy(iter);
 				return -1;
+			}
 		}
 		r = nftnl_rule_iter_next(iter);
 	}
Signature · 1 line
2.21.0
maintainer Applied
#1 lore raw
Quoted 2 lines · Phil Sutter

If batch_rule_add() fails, this function leaked the rule iterator object.

Applied, thanks Phil.