From: Vsevolod Stakhov Date: Sun, 26 Jun 2016 10:29:05 +0000 (+0100) Subject: [Fix] Fix parsing of braced IPv6 addresses X-Git-Tag: 1.3.0~250 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f24575ceec243ae947cd2e55a4b080891a8584d2;p=thirdparty%2Frspamd.git [Fix] Fix parsing of braced IPv6 addresses --- diff --git a/src/libutil/radix.c b/src/libutil/radix.c index 8771eed5fb..a91a82d199 100644 --- a/src/libutil/radix.c +++ b/src/libutil/radix.c @@ -142,7 +142,7 @@ gint rspamd_radix_add_iplist (const gchar *list, const gchar *separators, radix_compressed_t *tree, gconstpointer value) { - gchar *token, *ipnet, *err_str, **strv, **cur; + gchar *token, *ipnet, *err_str, **strv, **cur, *brace; struct in_addr ina; struct in6_addr ina6; guint k = G_MAXINT; @@ -176,17 +176,44 @@ rspamd_radix_add_iplist (const gchar *list, const gchar *separators, } /* Check IP */ - if (inet_pton (AF_INET, token, &ina) == 1) { - af = AF_INET; - } - else if (inet_pton (AF_INET6, token, &ina6) == 1) { - af = AF_INET6; + if (token[0] == '[') { + /* Braced IPv6 */ + brace = strrchr (token, ']'); + + if (brace != NULL) { + token ++; + *brace = '\0'; + + if (inet_pton (AF_INET6, token, &ina6) == 1) { + af = AF_INET6; + } + else { + msg_warn_radix ("invalid IP address: %s", token); + + cur ++; + continue; + } + } + else { + msg_warn_radix ("invalid IP address: %s", token); + + cur ++; + continue; + } } else { - msg_warn_radix ("invalid IP address: %s", token); + if (inet_pton (AF_INET, token, &ina) == 1) { + af = AF_INET; + } + else if (inet_pton (AF_INET6, token, &ina6) == 1) { + af = AF_INET6; + } + else { + msg_warn_radix ("invalid IP address: %s", token); - cur ++; - continue; + cur ++; + continue; + } } if (af == AF_INET) {