[sr-dev] git:master:f429e753: core: fix matching network addresses with bitmask non divisible to 8

Daniel-Constantin Mierla miconda at gmail.com
Tue Jul 7 11:16:36 CEST 2015


Module: kamailio
Branch: master
Commit: f429e753dfa750a604bfb0acb5068b47d0fbe142
URL: https://github.com/kamailio/kamailio/commit/f429e753dfa750a604bfb0acb5068b47d0fbe142

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2015-07-07T11:16:17+02:00

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

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

---

Modified: ip_addr.c

---

Diff:  https://github.com/kamailio/kamailio/commit/f429e753dfa750a604bfb0acb5068b47d0fbe142.diff
Patch: https://github.com/kamailio/kamailio/commit/f429e753dfa750a604bfb0acb5068b47d0fbe142.patch

---

diff --git a/ip_addr.c b/ip_addr.c
index 8504740..3412af9 100644
--- a/ip_addr.c
+++ b/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;
 }




More information about the sr-dev mailing list