Mercurial > dovecot > core-2.2
changeset 19534:25e892203e2b
lib: Fixed assert-crash with net_is_in_network(family=ipv6, family=0, ..)
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Mon, 04 Jan 2016 14:00:19 -0500 |
parents | 06825c099fa1 |
children | 60e922d0b318 |
files | src/lib/net.c src/lib/test-net.c |
diffstat | 2 files changed, 14 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/net.c Mon Jan 04 20:51:34 2016 +0200 +++ b/src/lib/net.c Mon Jan 04 14:00:19 2016 -0500 @@ -1125,7 +1125,7 @@ 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;
--- a/src/lib/test-net.c Mon Jan 04 20:51:34 2016 +0200 +++ b/src/lib/test-net.c Mon Jan 04 14:00:19 2016 -0500 @@ -46,6 +46,19 @@ 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(); }