]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Do not accept invalid ucl object types
authorVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 14 Aug 2023 09:53:45 +0000 (10:53 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 14 Aug 2023 09:53:45 +0000 (10:53 +0100)
Issue: #4571

src/libserver/cfg_utils.c
src/libserver/maps/map_helpers.c

index 8f41d8638127f061fc824f2af699c877e301e0d1..cdb1518a854583be6b53520e28acc52b1775b713 100644 (file)
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2023 Vsevolod Stakhov
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- *   http://www.apache.org/licenses/LICENSE-2.0
+ *    http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -2248,14 +2248,25 @@ rspamd_config_radix_from_ucl(struct rspamd_config *cfg, const ucl_object_t *obj,
                        it = ucl_object_iterate_new(cur_elt);
 
                        while ((cur = ucl_object_iterate_safe(it, true)) != NULL) {
-                               str = ucl_object_tostring(cur);
 
-                               if (!*target) {
-                                       *target = rspamd_map_helper_new_radix(
-                                               rspamd_map_add_fake(cfg, description, map_name));
-                               }
 
-                               rspamd_map_helper_insert_radix_resolve(*target, str, "");
+                               if (ucl_object_type(cur) == UCL_STRING) {
+                                       str = ucl_object_tostring(cur);
+                                       if (!*target) {
+                                               *target = rspamd_map_helper_new_radix(
+                                                       rspamd_map_add_fake(cfg, description, map_name));
+                                       }
+
+                                       rspamd_map_helper_insert_radix_resolve(*target, str, "");
+                               }
+                               else {
+                                       g_set_error(err,
+                                                               g_quark_from_static_string("rspamd-config"),
+                                                               EINVAL, "bad element inside array object for %s: expected string, got: %s",
+                                                               ucl_object_key(obj), ucl_object_type_to_string(ucl_object_type(cur)));
+                                       ucl_object_iterate_free(it);
+                                       return FALSE;
+                               }
                        }
 
                        ucl_object_iterate_free(it);
@@ -2755,11 +2766,11 @@ rspamd_config_libs(struct rspamd_external_libs_ctx *ctx,
 
        if (ctx != NULL) {
                if (cfg->local_addrs) {
-                       rspamd_config_radix_from_ucl(cfg, cfg->local_addrs,
-                                                                                "Local addresses",
-                                                                                (struct rspamd_radix_map_helper **) ctx->local_addrs,
-                                                                                NULL,
-                                                                                NULL, "local addresses");
+                       ret = rspamd_config_radix_from_ucl(cfg, cfg->local_addrs,
+                                                                                          "Local addresses",
+                                                                                          (struct rspamd_radix_map_helper **) ctx->local_addrs,
+                                                                                          NULL,
+                                                                                          NULL, "local addresses");
                }
 
                rspamd_free_zstd_dictionary(ctx->in_dict);
index 339fee7c8832b920c1bf083e92cb74bb31a6115f..be4b312ca4840b3e203c48f464d129170710434e 100644 (file)
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2018 Vsevolod Stakhov
+/*
+ * Copyright 2023 Vsevolod Stakhov
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- *   http://www.apache.org/licenses/LICENSE-2.0
+ *    http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -525,6 +525,13 @@ void rspamd_map_helper_insert_radix_resolve(gpointer st, gconstpointer key, gcon
        struct rspamd_map *map;
 
        map = r->map;
+
+       if (!key) {
+               msg_warn_map("cannot insert NULL value in the map: %s",
+                                        map->name);
+               return;
+       }
+
        tok.begin = key;
        tok.len = strlen(key);