From: Timo Sirainen Date: Mon, 4 Jan 2016 19:00:19 +0000 (-0500) Subject: lib: Fixed assert-crash with net_is_in_network(family=ipv6, family=0, ..) X-Git-Tag: 2.2.22.rc1~386 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3ad31bce46b1916b860d1b9fb7b4117b883b3f28;p=thirdparty%2Fdovecot%2Fcore.git lib: Fixed assert-crash with net_is_in_network(family=ipv6, family=0, ..) --- diff --git a/src/lib/net.c b/src/lib/net.c index f998cb9512..ae9b477037 100644 --- a/src/lib/net.c +++ b/src/lib/net.c @@ -1125,7 +1125,7 @@ bool net_is_in_network(const struct ip_addr *ip, ip = &tmp_ip; } - if (ip->family == 0) { + if (ip->family == 0 || net_ip->family == 0) { /* non-IPv4/IPv6 address (e.g. UNIX socket) never matches anything */ return FALSE; diff --git a/src/lib/test-net.c b/src/lib/test-net.c index ed89ac762b..6578f832e9 100644 --- a/src/lib/test-net.c +++ b/src/lib/test-net.c @@ -46,6 +46,19 @@ static void test_net_is_in_network(void) input[i].ret; test_out(t_strdup_printf("net_is_in_network(%u)", i), success); } + /* make sure non-IPv4 and non-IPv6 ip_addrs fail */ + test_assert(net_addr2ip("127.0.0.1", &ip) == 0); + net_ip = ip; + net_ip.family = 0; + test_assert(!net_is_in_network(&ip, &net_ip, 0)); + test_assert(!net_is_in_network(&net_ip, &ip, 0)); +#ifdef HAVE_IPV6 + test_assert(net_addr2ip("::1", &ip) == 0); + net_ip = ip; + net_ip.family = 0; + test_assert(!net_is_in_network(&ip, &net_ip, 0)); + test_assert(!net_is_in_network(&net_ip, &ip, 0)); +#endif test_end(); }