瀏覽代碼

core: fix matching network addresses with bitmask non divisible to 8

- reported by Kyle Kurz <[email protected]> for permissions module
Daniel-Constantin Mierla 10 年之前
父節點
當前提交
f429e753df
共有 1 個文件被更改,包括 5 次插入3 次删除
  1. 5 3
      ip_addr.c

+ 5 - 3
ip_addr.c

@@ -377,7 +377,8 @@ char* get_proto_name(unsigned int proto)
 int ip_addr_match_net(ip_addr_t *iaddr, ip_addr_t *naddr,
 		int mask)
 {
-	unsigned char c;
+	unsigned char ci;
+	unsigned char cn;
 	int i;
 	int mbytes;
 	int mbits;
@@ -420,8 +421,9 @@ int ip_addr_match_net(ip_addr_t *iaddr, ip_addr_t *naddr,
 	mbits = mask % 8;
 	if(mbits==0)
 		return 0;
-	c = naddr->u.addr[i] & (~((1 << (8 - mbits)) - 1));
-	if((iaddr->u.addr[i] & c) == c)
+	ci = iaddr->u.addr[i] & (~((1 << (8 - mbits)) - 1));
+	cn = naddr->u.addr[i] & (~((1 << (8 - mbits)) - 1));
+	if(ci == cn)
 		return 0;
 	return -1;
 }