Browse code

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

- reported by Kyle Kurz <kkurz@digium.com> for permissions module

Daniel-Constantin Mierla authored on 07/07/2015 09:14:31
Showing 1 changed files
... ...
@@ -377,7 +377,8 @@ char* get_proto_name(unsigned int proto)
377 377
 int ip_addr_match_net(ip_addr_t *iaddr, ip_addr_t *naddr,
378 378
 		int mask)
379 379
 {
380
-	unsigned char c;
380
+	unsigned char ci;
381
+	unsigned char cn;
381 382
 	int i;
382 383
 	int mbytes;
383 384
 	int mbits;
... ...
@@ -420,8 +421,9 @@ int ip_addr_match_net(ip_addr_t *iaddr, ip_addr_t *naddr,
420 421
 	mbits = mask % 8;
421 422
 	if(mbits==0)
422 423
 		return 0;
423
-	c = naddr->u.addr[i] & (~((1 << (8 - mbits)) - 1));
424
-	if((iaddr->u.addr[i] & c) == c)
424
+	ci = iaddr->u.addr[i] & (~((1 << (8 - mbits)) - 1));
425
+	cn = naddr->u.addr[i] & (~((1 << (8 - mbits)) - 1));
426
+	if(ci == cn)
425 427
 		return 0;
426 428
 	return -1;
427 429
 }