From 80570342976e1671730621db8eae318d18cceb99 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 25 Jun 2016 13:43:21 +0100 Subject: [PATCH] [Fix] Fix the case of multiple values keys --- src/libserver/cfg_utils.c | 107 ++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 52 deletions(-) diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index 299a852aa..34029664b 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -1653,69 +1653,72 @@ rspamd_config_radix_from_ucl (struct rspamd_config *cfg, { ucl_type_t type; ucl_object_iter_t it = NULL; - const ucl_object_t *cur; + const ucl_object_t *cur, *cur_elt; const gchar *str; - type = ucl_object_type (obj); - - switch (type) { - case UCL_STRING: - /* Either map or a list of IPs */ - str = ucl_object_tostring (obj); - - if (rspamd_map_is_map (str)) { - if (rspamd_map_add_from_ucl (cfg, cfg->local_addrs, + LL_FOREACH (obj, cur_elt) { + type = ucl_object_type (cur_elt); + + switch (type) { + case UCL_STRING: + /* Either map or a list of IPs */ + str = ucl_object_tostring (cur_elt); + + if (rspamd_map_is_map (str)) { + if (rspamd_map_add_from_ucl (cfg, cur_elt, + description, rspamd_radix_read, rspamd_radix_fin, + (void **)target) == NULL) { + g_set_error (err, g_quark_from_static_string ("rspamd-config"), + EINVAL, "bad map definition %s for %s", str, + ucl_object_key (obj)); + return FALSE; + } + } + else { + /* Just a list */ + if (!radix_add_generic_iplist (str, target)) { + g_set_error (err, g_quark_from_static_string ("rspamd-config"), + EINVAL, "bad map definition %s for %s", str, + ucl_object_key (obj)); + return FALSE; + } + } + break; + case UCL_OBJECT: + /* Should be a map description */ + if (rspamd_map_add_from_ucl (cfg, cur_elt, description, rspamd_radix_read, rspamd_radix_fin, (void **)target) == NULL) { g_set_error (err, g_quark_from_static_string ("rspamd-config"), - EINVAL, "bad map definition %s for %s", str, - ucl_object_key (obj)); - return FALSE; - } - } - else { - /* Just a list */ - if (!radix_add_generic_iplist (str, target)) { - g_set_error (err, g_quark_from_static_string ("rspamd-config"), - EINVAL, "bad map definition %s for %s", str, - ucl_object_key (obj)); + EINVAL, "bad map object for %s", ucl_object_key (obj)); return FALSE; } - } - break; - case UCL_OBJECT: - /* Should be a map description */ - if (rspamd_map_add_from_ucl (cfg, cfg->local_addrs, - description, rspamd_radix_read, rspamd_radix_fin, - (void **)target) == NULL) { - g_set_error (err, g_quark_from_static_string ("rspamd-config"), - EINVAL, "bad map object for %s", ucl_object_key (obj)); - return FALSE; - } - break; - case UCL_ARRAY: - /* List of IP addresses */ - while ((cur = ucl_iterate_object (obj, &it, true)) != NULL) { - str = ucl_object_tostring (cur); - - if (str == NULL || !radix_add_generic_iplist (str, target)) { - g_set_error (err, g_quark_from_static_string ("rspamd-config"), - EINVAL, "bad map element %s for %s", str, - ucl_object_key (obj)); + break; + case UCL_ARRAY: + /* List of IP addresses */ + while ((cur = ucl_iterate_object (cur_elt, &it, true)) != NULL) { + str = ucl_object_tostring (cur); + + if (str == NULL || !radix_add_generic_iplist (str, target)) { + g_set_error (err, g_quark_from_static_string ("rspamd-config"), + EINVAL, "bad map element %s for %s", str, + ucl_object_key (obj)); + + if (*target) { + radix_destroy_compressed (*target); + } - if (*target) { - radix_destroy_compressed (*target); + return FALSE; } - - return FALSE; } + break; + default: + g_set_error (err, g_quark_from_static_string ("rspamd-config"), + EINVAL, "bad map type %s for %s", + ucl_object_type_to_string (type), + ucl_object_key (obj)); + return FALSE; } - break; - default: - g_set_error (err, g_quark_from_static_string ("rspamd-config"), - EINVAL, "bad map type %s for %s", ucl_object_type_to_string (type), - ucl_object_key (obj)); - return FALSE; } return TRUE; -- 2.39.5