dovecot-2.2: net_is_in_network(): Don't assert-crash with invali...

dovecot at dovecot.org dovecot at dovecot.org
Tue Mar 19 12:39:59 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/790bb5dfadc6
changeset: 16043:790bb5dfadc6
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Mar 19 12:39:43 2013 +0200
description:
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.

diffstat:

 src/lib/net.c |  5 +++++
 src/lib/net.h |  3 ++-
 2 files changed, 7 insertions(+), 1 deletions(-)

diffs (28 lines):

diff -r ea6636b36b1c -r 790bb5dfadc6 src/lib/net.c
--- 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;
diff -r ea6636b36b1c -r 790bb5dfadc6 src/lib/net.h
--- 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;
 


More information about the dovecot-cvs mailing list