commit 79fe034: [Fix] Fix configuring symbols without scores

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Aug 15 12:21:03 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-08-15 13:15:58 +0100
URL: https://github.com/rspamd/rspamd/commit/79fe034e7cdbb09630e2bd5259421f5114fa4b81 (HEAD -> master)

[Fix] Fix configuring symbols without scores

---
 src/libserver/cfg_file.h  |  2 +-
 src/libserver/cfg_rcl.c   |  2 +-
 src/libserver/cfg_utils.c | 40 +++++++++++++++++++++++++++-------------
 3 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index d4855e032..1fd56441c 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -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;
 };
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index ba1b614a0..5a10a6c3e 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -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;
 
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index 1872a68ec..f2234f1ed 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -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);
 


More information about the Commits mailing list