From: Martin Mares Date: Tue, 4 Jun 2019 16:35:50 +0000 (+0200) Subject: libutil: Fix parsing of address "IPv6:::1" X-Git-Tag: 2.0~813^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e68ea4ea38376ba0eedf36578c3499159e675c90;p=rspamd.git libutil: Fix parsing of address "IPv6:::1" Dropping of leading colon must be performed after the "IPv6:" prefix is stripped. Also fixed a couple of wrong comments. --- diff --git a/src/libutil/addr.c b/src/libutil/addr.c index 7fa634f6f..4babfb1d2 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -510,19 +510,11 @@ rspamd_parse_inet_address_ip6 (const guchar *text, gsize len, gpointer target) g_assert (text != NULL); g_assert (target != NULL); + p = text; if (len == 0) { len = strlen (text); } - /* Ignore trailing semicolon */ - if (text[0] == ':') { - p = text + 1; - len--; - } - else { - p = text; - } - /* Check IPv6 scope */ if ((percent = memchr (p, '%', len)) != NULL && percent > p) { len = percent - p; /* Ignore scope */ @@ -535,6 +527,12 @@ rspamd_parse_inet_address_ip6 (const guchar *text, gsize len, gpointer target) len -= sizeof ("IPv6:") - 1; } + /* Ignore leading colon */ + if (len > 0 && *p == ':') { + p++; + len--; + } + for (/* void */; len; len--) { t = *p++; @@ -580,7 +578,7 @@ rspamd_parse_inet_address_ip6 (const guchar *text, gsize len, gpointer target) } if (++nibbles > 4) { - /* Too many dots */ + /* Too many digits */ return FALSE; }