aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-26 11:29:05 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-26 11:29:05 +0100
commitf24575ceec243ae947cd2e55a4b080891a8584d2 (patch)
tree4329a183d1e86087dbe57b8c21d5a4c3bc0aff41
parentbffedb45f32b0e68b3d679e8654d1c13335b8790 (diff)
downloadrspamd-f24575ceec243ae947cd2e55a4b080891a8584d2.tar.gz
rspamd-f24575ceec243ae947cd2e55a4b080891a8584d2.zip
[Fix] Fix parsing of braced IPv6 addresses
-rw-r--r--src/libutil/radix.c45
1 files changed, 36 insertions, 9 deletions
diff --git a/src/libutil/radix.c b/src/libutil/radix.c
index 8771eed5f..a91a82d19 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) {