]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Some fixes to allow empty symbols_enabled/disabled
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 29 May 2020 14:18:55 +0000 (15:18 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 29 May 2020 14:18:55 +0000 (15:18 +0100)
src/libserver/rspamd_symcache.c
src/lua/lua_config.c

index 0bd68fca63640f43e0fbdf3cddbddcef9c73eb32..624d1c3823f91647ee33765c275e9f8570d4c78d 100644 (file)
@@ -3531,10 +3531,8 @@ rspamd_symcache_get_forbidden_settings_ids (struct rspamd_symcache *cache,
                return item->allowed_ids.dyn.n;
        }
        else {
-               while (item->forbidden_ids.st[cnt] != 0) {
+               while (item->forbidden_ids.st[cnt] != 0 && cnt < G_N_ELEMENTS (item->allowed_ids.st)) {
                        cnt ++;
-
-                       g_assert (cnt < G_N_ELEMENTS (item->allowed_ids.st));
                }
 
                *nids = cnt;
@@ -3543,7 +3541,7 @@ rspamd_symcache_get_forbidden_settings_ids (struct rspamd_symcache *cache,
        }
 }
 
-/* Usable for near-sorted ids list */
+/* Insertion sort: usable for near-sorted ids list */
 static inline void
 rspamd_ids_insertion_sort (guint *a, guint n)
 {
@@ -3571,7 +3569,7 @@ rspamd_symcache_add_id_to_list (rspamd_mempool_t *pool,
        if (ls->st[0] == -1) {
                /* Dynamic array */
                if (ls->dyn.len < ls->dyn.allocated) {
-                       /* Trivial, append + qsort */
+                       /* Trivial, append + sort */
                        ls->dyn.n[ls->dyn.len++] = id;
                }
                else {
@@ -3590,7 +3588,7 @@ rspamd_symcache_add_id_to_list (rspamd_mempool_t *pool,
        }
        else {
                /* Static part */
-               while (ls->st[cnt] != 0) {
+               while (ls->st[cnt] != 0 && cnt < G_N_ELEMENTS (ls->st)) {
                        cnt ++;
                }
 
index cfeb6e68d0e0586214a2c01208ea4098cb048980..a605f2fac3cd4742246737e0c44b17826e45168f 100644 (file)
@@ -3796,6 +3796,30 @@ lua_config_register_finish_script (lua_State *L)
        return 0;
 }
 
+static inline bool
+rspamd_lua_config_check_settings_symbols_object (const ucl_object_t *obj)
+{
+       if (obj == NULL) {
+               /* Semantically valid */
+               return true;
+       }
+
+       if (ucl_object_type (obj) == UCL_OBJECT) {
+               /* Key-value mapping - should be okay */
+               return true;
+       }
+
+       if (ucl_object_type (obj) == UCL_ARRAY) {
+               /* Okay if empty */
+               if (obj->len == 0) {
+                       return true;
+               }
+       }
+
+       /* Everything else not okay */
+       return false;
+}
+
 static gint
 lua_config_register_settings_id (lua_State *L)
 {
@@ -3809,7 +3833,7 @@ lua_config_register_settings_id (lua_State *L)
 
                sym_enabled = ucl_object_lua_import (L, 3);
 
-               if (sym_enabled != NULL && ucl_object_type (sym_enabled) != UCL_OBJECT) {
+               if (!rspamd_lua_config_check_settings_symbols_object (sym_enabled)) {
                        ucl_object_unref (sym_enabled);
 
                        return luaL_error (L, "invalid symbols enabled");
@@ -3817,7 +3841,7 @@ lua_config_register_settings_id (lua_State *L)
 
                sym_disabled = ucl_object_lua_import (L, 4);
 
-               if (sym_disabled != NULL && ucl_object_type (sym_disabled) != UCL_OBJECT) {
+               if (!rspamd_lua_config_check_settings_symbols_object (sym_disabled)) {
                        ucl_object_unref (sym_enabled);
                        ucl_object_unref (sym_disabled);