changeset 16043:790bb5dfadc6

net_is_in_network(): Don't assert-crash with invalid IP. It's probably better to do the check here instead of remembering for caller to do the check.
author Timo Sirainen <tss@iki.fi>
date Tue, 19 Mar 2013 12:39:43 +0200
parents ea6636b36b1c
children 2396eb0a3e3f
files src/lib/net.c src/lib/net.h
diffstat 2 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/net.c	Tue Mar 19 12:18:25 2013 +0200
+++ b/src/lib/net.c	Tue Mar 19 12:39:43 2013 +0200
@@ -984,6 +984,11 @@
 		ip = &tmp_ip;
 	}
 
+	if (ip->family == 0) {
+		/* non-IPv4/IPv6 address (e.g. UNIX socket) never matches
+		   anything */
+		return FALSE;
+	}
 	if (IPADDR_IS_V4(ip) != IPADDR_IS_V4(net_ip)) {
 		/* one is IPv6 and one is IPv4 */
 		return FALSE;
--- a/src/lib/net.h	Tue Mar 19 12:18:25 2013 +0200
+++ b/src/lib/net.h	Tue Mar 19 12:39:43 2013 +0200
@@ -145,7 +145,8 @@
 int net_parse_range(const char *network, struct ip_addr *ip_r,
 		    unsigned int *bits_r);
 /* Returns TRUE if ip is in net_ip/bits network. IPv6 mapped IPv4 addresses
-   are converted to plain IPv4 addresses before matching. */
+   are converted to plain IPv4 addresses before matching. Invalid IPs
+   (family=0) never match anything. */
 bool net_is_in_network(const struct ip_addr *ip, const struct ip_addr *net_ip,
 		       unsigned int bits) ATTR_PURE;