]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix configuring symbols without scores
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 15 Aug 2019 12:15:58 +0000 (13:15 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 15 Aug 2019 12:15:58 +0000 (13:15 +0100)
src/libserver/cfg_file.h
src/libserver/cfg_rcl.c
src/libserver/cfg_utils.c

index d4855e032d1963384cdeac72073b6794369a5fbd..1fd56441c2a381ee35f022cad0612048eaac1660 100644 (file)
@@ -141,7 +141,7 @@ struct rspamd_symbol {
        guint priority;
        struct rspamd_symbols_group *gr; /* Main group */
        GPtrArray *groups; /* Other groups */
-       enum rspamd_symbol_flags flags;
+       guint flags;
        struct rspamd_symcache_item *cache_item;
        gint nshots;
 };
index ba1b614a0f1e0c08f66261d045c5521e668daf2b..5a10a6c3e75a5bcd9d4104ba44e88fd3b1a8767c 100644 (file)
@@ -424,7 +424,7 @@ rspamd_rcl_symbol_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
        struct rspamd_config *cfg;
        const ucl_object_t *elt;
        const gchar *description = NULL;
-       gdouble score = 0.0;
+       gdouble score = NAN;
        guint priority = 1, flags = 0;
        gint nshots;
 
index 1872a68ec5aec51d474540ae61197dc371058a58..f2234f1edb406e2c2a1fa1ad78a82f23a0169821 100644 (file)
@@ -1554,6 +1554,12 @@ rspamd_config_new_symbol (struct rspamd_config *cfg, const gchar *symbol,
                rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_symbol));
        score_ptr = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (gdouble));
 
+       if (isnan (score)) {
+               msg_warn_config ("score is not defined for symbol %s, set it to zero",
+                               symbol);
+               score = 0.0;
+       }
+
        *score_ptr = score;
        sym_def->score = score;
        sym_def->weight_ptr = score_ptr;
@@ -1603,9 +1609,12 @@ rspamd_config_new_symbol (struct rspamd_config *cfg, const gchar *symbol,
 gboolean
 rspamd_config_add_symbol (struct rspamd_config *cfg,
                                                  const gchar *symbol,
-                                                 gdouble score, const gchar *description,
+                                                 gdouble score,
+                                                 const gchar *description,
                                                  const gchar *group,
-                                                 guint flags, guint priority, gint nshots)
+                                                 guint flags,
+                                                 guint priority,
+                                                 gint nshots)
 {
        struct rspamd_symbol *sym_def;
        struct rspamd_symbols_group *sym_group;
@@ -1662,17 +1671,22 @@ rspamd_config_add_symbol (struct rspamd_config *cfg,
                        return FALSE;
                }
                else {
-                       msg_debug_config ("symbol %s has been already registered with "
-                                       "priority %ud, override it with new priority: %ud, "
-                                       "old score: %.2f, new score: %.2f",
-                                       symbol,
-                                       sym_def->priority,
-                                       priority,
-                                       sym_def->score,
-                                       score);
 
-                       *sym_def->weight_ptr = score;
-                       sym_def->score = score;
+                       if (!isnan (score)) {
+                               msg_debug_config ("symbol %s has been already registered with "
+                                                                 "priority %ud, override it with new priority: %ud, "
+                                                                 "old score: %.2f, new score: %.2f",
+                                               symbol,
+                                               sym_def->priority,
+                                               priority,
+                                               sym_def->score,
+                                               score);
+
+                               *sym_def->weight_ptr = score;
+                               sym_def->score = score;
+                               sym_def->priority = priority;
+                       }
+
                        sym_def->flags = flags;
                        sym_def->nshots = nshots;
 
@@ -1681,7 +1695,6 @@ rspamd_config_add_symbol (struct rspamd_config *cfg,
                                                description);
                        }
 
-                       sym_def->priority = priority;
 
                        /* We also check group information in this case */
                        if (group != NULL && sym_def->gr != NULL &&
@@ -1707,6 +1720,7 @@ rspamd_config_add_symbol (struct rspamd_config *cfg,
                }
        }
 
+       /* This is called merely when we have an undefined symbol */
        rspamd_config_new_symbol (cfg, symbol, score, description,
                        group, flags, priority, nshots);