]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Implement more strict configuration tests
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 3 Dec 2018 14:19:39 +0000 (14:19 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 3 Dec 2018 14:19:39 +0000 (14:19 +0000)
src/libserver/cfg_rcl.c
src/libserver/cfg_utils.c
src/plugins/regexp.c
src/rspamadm/configtest.c

index 3df4ce05d23472b3da8173f17894912d7bfc27e2..b8f7b9738ab1d208f7424feade4616c5d2b78bca 100644 (file)
@@ -381,40 +381,108 @@ rspamd_rcl_symbol_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
        nshots = cfg->default_max_shots;
 
        if ((elt = ucl_object_lookup (obj, "one_shot")) != NULL) {
+               if (ucl_object_type (elt) != UCL_BOOLEAN) {
+                       g_set_error (err,
+                                       CFG_RCL_ERROR,
+                                       EINVAL,
+                                       "one_shot attribute is not boolean for symbol: '%s'",
+                                       key);
+
+                       return FALSE;
+               }
                if (ucl_object_toboolean (elt)) {
                        nshots = 1;
                }
        }
 
        if ((elt = ucl_object_lookup (obj, "any_shot")) != NULL) {
+               if (ucl_object_type (elt) != UCL_BOOLEAN) {
+                       g_set_error (err,
+                                       CFG_RCL_ERROR,
+                                       EINVAL,
+                                       "any_shot attribute is not boolean for symbol: '%s'",
+                                       key);
+
+                       return FALSE;
+               }
                if (ucl_object_toboolean (elt)) {
                        nshots = -1;
                }
        }
 
        if ((elt = ucl_object_lookup (obj, "one_param")) != NULL) {
+               if (ucl_object_type (elt) != UCL_BOOLEAN) {
+                       g_set_error (err,
+                                       CFG_RCL_ERROR,
+                                       EINVAL,
+                                       "one_param attribute is not boolean for symbol: '%s'",
+                                       key);
+
+                       return FALSE;
+               }
+
                if (ucl_object_toboolean (elt)) {
                        flags |= RSPAMD_SYMBOL_FLAG_ONEPARAM;
                }
        }
 
        if ((elt = ucl_object_lookup (obj, "ignore")) != NULL) {
+               if (ucl_object_type (elt) != UCL_BOOLEAN) {
+                       g_set_error (err,
+                                       CFG_RCL_ERROR,
+                                       EINVAL,
+                                       "ignore attribute is not boolean for symbol: '%s'",
+                                       key);
+
+                       return FALSE;
+               }
+
                if (ucl_object_toboolean (elt)) {
                        flags |= RSPAMD_SYMBOL_FLAG_IGNORE;
                }
        }
 
        if ((elt = ucl_object_lookup (obj, "nshots")) != NULL) {
+               if (ucl_object_type (elt) != UCL_FLOAT && ucl_object_type (elt) != UCL_INT) {
+                       g_set_error (err,
+                                       CFG_RCL_ERROR,
+                                       EINVAL,
+                                       "nshots attribute is not numeric for symbol: '%s'",
+                                       key);
+
+                       return FALSE;
+               }
+
                nshots = ucl_object_toint (elt);
        }
 
        elt = ucl_object_lookup_any (obj, "score", "weight", NULL);
        if (elt) {
+               if (ucl_object_type (elt) != UCL_FLOAT && ucl_object_type (elt) != UCL_INT) {
+                       g_set_error (err,
+                                       CFG_RCL_ERROR,
+                                       EINVAL,
+                                       "score attribute is not numeric for symbol: '%s'",
+                                       key);
+
+                       return FALSE;
+               }
+
                score = ucl_object_todouble (elt);
        }
 
        elt = ucl_object_lookup (obj, "priority");
        if (elt) {
+               if (ucl_object_type (elt) != UCL_FLOAT && ucl_object_type (elt) != UCL_INT) {
+                       g_set_error (err,
+                                       CFG_RCL_ERROR,
+                                       EINVAL,
+                                       "priority attribute is not numeric for symbol: '%s'",
+                                       key);
+
+                       return FALSE;
+               }
+
                priority = ucl_object_toint (elt);
        }
        else {
index 550e4b730e62893a86f9422de8076a94cf4cc7c4..ec2e48786fc93c2a95f656358ccad7a3026f1ef9 100644 (file)
@@ -1470,6 +1470,7 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig)
        module_t *mod, **pmod;
        guint i = 0;
        struct module_ctx *mod_ctx, *cur_ctx;
+       gboolean ret = TRUE;
 
        /* Init all compiled modules */
 
@@ -1504,11 +1505,19 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig)
                        mod_ctx->enabled = rspamd_config_is_module_enabled (cfg, mod->name);
 
                        if (reconfig) {
-                               (void)mod->module_reconfig_func (cfg);
-                               msg_info_config ("reconfig of %s", mod->name);
+                               if (!mod->module_reconfig_func (cfg)) {
+                                       msg_err_config ("reconfig of %s failed!", mod->name);
+                               }
+                               else {
+                                       msg_info_config ("reconfig of %s", mod->name);
+                               }
+
                        }
                        else {
-                               (void)mod->module_config_func (cfg);
+                               if (!mod->module_config_func (cfg)) {
+                                       msg_info_config ("config of %s failed!", mod->name);
+                                       ret = FALSE;
+                               }
                        }
                }
 
@@ -1519,7 +1528,9 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig)
                cur = g_list_next (cur);
        }
 
-       return rspamd_init_lua_filters (cfg, 0);
+       ret = rspamd_init_lua_filters (cfg, 0) && ret;
+
+       return ret;
 }
 
 static void
index b40c9c4686d5f3b88bf2f6de08e9dada8291b63b..897bbd2776e85432e09e23a8e775c9dda51a4358 100644 (file)
@@ -279,39 +279,96 @@ regexp_module_config (struct rspamd_config *cfg)
                                elt = ucl_object_lookup (value, "score");
 
                                if (elt) {
-                                       score = ucl_object_todouble (elt);
+                                       if (ucl_object_type (elt) != UCL_FLOAT && ucl_object_type (elt) != UCL_INT) {
+                                               msg_err_config (
+                                                               "score attribute is not numeric for symbol: '%s'",
+                                                               cur_item->symbol);
+
+                                               res = FALSE;
+                                       }
+                                       else {
+                                               score = ucl_object_todouble (elt);
+                                       }
                                }
 
                                elt = ucl_object_lookup (value, "one_shot");
 
                                if (elt) {
-                                       if (ucl_object_toboolean (elt)) {
-                                               nshots = 1;
+                                       if (ucl_object_type (elt) != UCL_BOOLEAN) {
+                                               msg_err_config (
+                                                               "one_shot attribute is not numeric for symbol: '%s'",
+                                                               cur_item->symbol);
+
+                                               res = FALSE;
+                                       }
+                                       else {
+                                               if (ucl_object_toboolean (elt)) {
+                                                       nshots = 1;
+                                               }
                                        }
                                }
 
                                if ((elt = ucl_object_lookup (value, "any_shot")) != NULL) {
-                                       if (ucl_object_toboolean (elt)) {
-                                               nshots = -1;
+                                       if (ucl_object_type (elt) != UCL_BOOLEAN) {
+                                               msg_err_config (
+                                                               "any_shot attribute is not numeric for symbol: '%s'",
+                                                               cur_item->symbol);
+
+                                               res = FALSE;
+                                       }
+                                       else {
+                                               if (ucl_object_toboolean (elt)) {
+                                                       nshots = -1;
+                                               }
                                        }
                                }
 
                                if ((elt = ucl_object_lookup (value, "nshots")) != NULL) {
-                                       nshots = ucl_object_toint (elt);
+                                       if (ucl_object_type (elt) != UCL_FLOAT && ucl_object_type (elt) != UCL_INT) {
+                                               msg_err_config (
+                                                               "nshots attribute is not numeric for symbol: '%s'",
+                                                               cur_item->symbol);
+
+                                               res = FALSE;
+                                       }
+                                       else {
+                                               nshots = ucl_object_toint (elt);
+                                       }
                                }
 
                                elt = ucl_object_lookup (value, "one_param");
 
                                if (elt) {
-                                       if (ucl_object_toboolean (elt)) {
-                                               flags |= RSPAMD_SYMBOL_FLAG_ONEPARAM;
+                                       if (ucl_object_type (elt) != UCL_BOOLEAN) {
+                                               msg_err_config (
+                                                               "one_param attribute is not numeric for symbol: '%s'",
+                                                               cur_item->symbol);
+
+                                               res = FALSE;
+                                       }
+                                       else {
+                                               if (ucl_object_toboolean (elt)) {
+                                                       flags |= RSPAMD_SYMBOL_FLAG_ONEPARAM;
+                                               }
                                        }
                                }
 
                                elt = ucl_object_lookup (value, "priority");
 
                                if (elt) {
-                                       priority = ucl_object_toint (elt);
+                                       if (ucl_object_type (elt) != UCL_FLOAT && ucl_object_type (elt) != UCL_INT) {
+                                               msg_err_config (
+                                                               "priority attribute is not numeric for symbol: '%s'",
+                                                               cur_item->symbol);
+
+                                               res = FALSE;
+                                       }
+                                       else {
+                                               priority = ucl_object_toint (elt);
+                                       }
+                               }
+                               else {
+                                       priority = ucl_object_get_priority (value) + 1;
                                }
 
                                rspamd_config_add_symbol (cfg, cur_item->symbol,
index 0fe0a23adb9715c2b5ef74855caaf3aad1091386..db9a8d604b239f8c6d36c0e3d3bad647f0b4455e 100644 (file)
@@ -156,7 +156,7 @@ rspamadm_configtest (gint argc, gchar **argv, const struct rspamadm_command *cmd
                        ret = rspamd_config_post_load (cfg, RSPAMD_CONFIG_INIT_SYMCACHE);
                }
 
-               if (!rspamd_symcache_validate (rspamd_main->cfg->cache,
+               if (ret && !rspamd_symcache_validate (rspamd_main->cfg->cache,
                                rspamd_main->cfg,
                                FALSE)) {
                        ret = FALSE;