From 36973d12c579eba656203614d092ffd47661596e Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Sun, 5 Mar 2017 09:45:37 +0100 Subject: [PATCH] ipops: proper return code for ip_is_in_subnet() - returning 0 stopos the config execution, do -1 instead - reported by A Messina, GH #1018 --- src/modules/ipops/ipops_mod.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/modules/ipops/ipops_mod.c b/src/modules/ipops/ipops_mod.c index 0e6f04efe63..150b9622d50 100644 --- a/src/modules/ipops/ipops_mod.c +++ b/src/modules/ipops/ipops_mod.c @@ -77,7 +77,8 @@ MODULE_VERSION int _compare_ips(char*, size_t, enum enum_ip_type, char*, size_t, enum enum_ip_type); int _compare_ips_v4(struct in_addr *ip, char*, size_t); int _compare_ips_v6(struct in6_addr *ip, char*, size_t); -int _ip_is_in_subnet(char *ip1, size_t len1, enum enum_ip_type ip1_type, char *ip2, size_t len2, enum enum_ip_type ip2_type, int netmask); +int _ip_is_in_subnet(char *ip1, size_t len1, enum enum_ip_type ip1_type, + char *ip2, size_t len2, enum enum_ip_type ip2_type, int netmask); int _ip_is_in_subnet_v4(struct in_addr *ip, char *net, size_t netlen, int netmask); int _ip_is_in_subnet_v6(struct in6_addr *ip, char *net, size_t netlen, int netmask); int _ip_is_in_subnet_str(void *ip, enum enum_ip_type type, char *s, int slen); @@ -304,8 +305,10 @@ int _compare_ips_v6(struct in6_addr *ip, char* ip2, size_t len2) return 0; } -/*! \brief Return 1 if IP1 is in the subnet given by IP2 and the netmask, 0 otherwise. */ -int _ip_is_in_subnet(char *ip1, size_t len1, enum enum_ip_type ip1_type, char *ip2, size_t len2, enum enum_ip_type ip2_type, int netmask) +/*! \brief Return 1 if IP1 is in the subnet given by IP2 and the netmask, + * 0 otherwise. */ +int _ip_is_in_subnet(char *ip1, size_t len1, enum enum_ip_type ip1_type, + char *ip2, size_t len2, enum enum_ip_type ip2_type, int netmask) { struct in_addr in_addr1, in_addr2; struct in6_addr in6_addr1, in6_addr2; @@ -875,7 +878,9 @@ static int w_ip_is_in_subnet(struct sip_msg* _msg, char* _s1, char* _s2) if((ret = _ip_is_in_subnet_str_trimmed(ip,ip1_type,b,e))>0) return ret; } e = string2.s+string2.len; - return _ip_is_in_subnet_str_trimmed(ip,ip1_type,b,e); + ret = _ip_is_in_subnet_str_trimmed(ip,ip1_type,b,e); + if(ret==0) return -1; + return ret; }