Skip to contentSkip to conversation

iptables: xtables_ipmask_to_numeric incorrect with non-CIDR masks

PATCH Applied Phil Oester 2 participants 2 messages Sep 26, 2013 – Sep 27, 2013 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iptables: xtables_ipmask_to_numeric incorrect with non-CIDR masks

As pointed out by Peter Hoelsken, rules created with non-standard masks such as 0.255.0.0, 0.0.255.0, etc. are displayed when output with iptables -L in CIDR notation as -1. This is because the cidr variable in xtables_ipmask_to_numeric is unsigned, and the return value of -1 from xtables_ipmask_to_cidr is therefore converted to 4294967295. Add a cast to workaround the issue.

This closes netfilter bugzilla #854.

libxtables/xtables.c +1 -1
index ef5bc07..8437baf 100644
@@ -1243,7 +1243,7 @@ const char *xtables_ipmask_to_numeric(const struct in_addr *mask)
 	uint32_t cidr;
 
 	cidr = xtables_ipmask_to_cidr(mask);
-	if (cidr < 0) {
+	if (cidr == (unsigned int)-1) {
 		/* mask was not a decent combination of 1's and 0's */
 		sprintf(buf, "/%s", xtables_ipaddr_to_numeric(mask));
 		return buf;
maintainer Applied
#1 lore raw
Quoted 7 lines · Phil Oester

As pointed out by Peter Hoelsken, rules created with non-standard masks such as 0.255.0.0, 0.0.255.0, etc. are displayed when output with iptables -L in CIDR notation as -1. This is because the cidr variable in xtables_ipmask_to_numeric is unsigned, and the return value of -1 from xtables_ipmask_to_cidr is therefore converted to 4294967295. Add a cast to workaround the issue.

This closes netfilter bugzilla #854.

Applied, thanks Phil!