commit b3073d9: [Minor] Deal with unknown weight more carefully to avoid special meaning of 0

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Jan 15 12:28:04 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-01-15 12:24:25 +0000
URL: https://github.com/rspamd/rspamd/commit/b3073d94bdcfabc37aeb27678c996a554c9f1df7

[Minor] Deal with unknown weight more carefully to avoid special meaning of 0
The special unknown weight must be NAN not 0.0

---
 src/libserver/cfg_utils.c       | 1 +
 src/libserver/rspamd_symcache.c | 5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index 67ceb5df8..44cdbc84f 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -171,6 +171,7 @@ rspamd_config_new (enum rspamd_config_init_flags flags)
 	cfg->dns_retransmits = 5;
 	/* 16 sockets per DNS server */
 	cfg->dns_io_per_server = 16;
+	cfg->unknown_weight = NAN;
 
 	/* Add all internal actions to keep compatibility */
 	for (int i = METRIC_ACTION_REJECT; i < METRIC_ACTION_MAX; i ++) {
diff --git a/src/libserver/rspamd_symcache.c b/src/libserver/rspamd_symcache.c
index d1fb68672..4335ada68 100644
--- a/src/libserver/rspamd_symcache.c
+++ b/src/libserver/rspamd_symcache.c
@@ -1438,7 +1438,7 @@ rspamd_symcache_validate_cb (gpointer k, gpointer v, gpointer ud)
 			(SYMBOL_TYPE_NORMAL|SYMBOL_TYPE_VIRTUAL|SYMBOL_TYPE_COMPOSITE|SYMBOL_TYPE_CLASSIFIER))
 			&& g_hash_table_lookup (cfg->symbols, item->symbol) == NULL) {
 
-		if (cfg->unknown_weight != 0) {
+		if (!isnan(cfg->unknown_weight)) {
 
 			skipped = FALSE;
 			item->st->weight = cfg->unknown_weight;
@@ -1448,7 +1448,8 @@ rspamd_symcache_validate_cb (gpointer k, gpointer v, gpointer ud)
 			s->weight_ptr = &item->st->weight;
 			g_hash_table_insert (cfg->symbols, item->symbol, s);
 
-			msg_info_cache ("adding unknown symbol %s", item->symbol);
+			msg_info_cache ("adding unknown symbol %s with weight: %.2f",
+					item->symbol, cfg->unknown_weight);
 			ghost = FALSE;
 		}
 		else {


More information about the Commits mailing list