]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Make dynamic conf more NaN aware
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 19 Mar 2018 13:25:44 +0000 (13:25 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 19 Mar 2018 13:25:58 +0000 (13:25 +0000)
src/controller.c
src/libserver/dynamic_cfg.c

index 0443062a11c37910923008d5f71832b2c8aa5fba..09b446e8cb87b48f35a076b43580f4a5820b9ea9 100644 (file)
@@ -2184,8 +2184,18 @@ rspamd_controller_handle_saveactions (
                        act = METRIC_ACTION_GREYLIST;
                        break;
                }
-               score = ucl_object_todouble (cur);
-               if (session->cfg->actions[act].score != score) {
+
+               if (ucl_object_type (cur) == UCL_NULL) {
+                       /* Assume NaN */
+                       score = NAN;
+               }
+               else {
+                       score = ucl_object_todouble (cur);
+               }
+
+
+               if ((isnan (session->cfg->actions[act].score) != isnan (score)) ||
+                               (session->cfg->actions[act].score != score)) {
                        add_dynamic_action (ctx->cfg, DEFAULT_METRIC, act, score);
                        added ++;
                }
index 3f0d490f4d836dccf9800a0cca159cd9a1e876a6..1211585261a11559953981806b31149f652d2bf0 100644 (file)
@@ -21,6 +21,8 @@
 #include "unix-std.h"
 #include "lua/lua_common.h"
 
+#include <math.h>
+
 struct config_json_buf {
        GString *buf;
        struct rspamd_config *cfg;
@@ -95,9 +97,11 @@ apply_dynamic_conf (const ucl_object_t *top, struct rspamd_config *cfg)
                        ucl_object_iter_t nit = NULL;
 
                        while ((it_val = ucl_object_iterate (cur_nm, &nit, true))) {
-                               if (ucl_object_lookup (it_val, "name") &&
-                                               ucl_object_lookup (it_val, "value")) {
-                                       name = ucl_object_tostring (ucl_object_lookup (it_val, "name"));
+                               const ucl_object_t *n = ucl_object_lookup (it_val, "name");
+                               const ucl_object_t *v = ucl_object_lookup (it_val, "value");
+
+                               if (n != NULL && v != NULL) {
+                                       name = ucl_object_tostring (n);
 
                                        if (!name || !rspamd_action_from_str (name, &test_act)) {
                                                msg_err ("unknown action: %s",
@@ -105,8 +109,15 @@ apply_dynamic_conf (const ucl_object_t *top, struct rspamd_config *cfg)
                                                                                "name")));
                                                continue;
                                        }
-                                       nscore = ucl_object_todouble (ucl_object_lookup (it_val,
-                                                       "value"));
+
+
+                                       if (ucl_object_type (v) == UCL_NULL) {
+                                               nscore = NAN;
+                                       }
+                                       else {
+                                               nscore = ucl_object_todouble (v);
+                                       }
+
                                        rspamd_config_set_action_score (cfg, name, nscore, priority);
                                }
                                else {