]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Preserve UNSCORED flag when config defines symbol without score
authorVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 13 Feb 2026 17:18:39 +0000 (17:18 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 13 Feb 2026 17:18:39 +0000 (17:18 +0000)
When rspamd_config_add_symbol was called for an existing symbol without
a score (NAN), line 1811 unconditionally replaced all flags, clearing
RSPAMD_SYMBOL_FLAG_UNSCORED. This caused Lua-registered scores to be
ignored: if a symbol appeared in config (e.g. groups.conf) without a
score, the UNSCORED flag was lost, and the Lua score-setting block in
lua_config_register_symbol_from_table was skipped, leaving score at 0.

Now flags are updated correctly in both cases:
- Real score provided: flags fully replaced with UNSCORED cleared
- NAN score: flags updated but UNSCORED preserved from existing symbol

Also initialize score to NAN in lua_config_set_metric_symbol to avoid
passing uninitialized stack garbage to rspamd_config_add_symbol.

src/libserver/cfg_utils.cxx
src/lua/lua_config.c

index a5871a87cc6cb11d65cdf40a4c36440dda32b31f..420cc70ab38af7f04e371d179dd9fc508a0c580e 100644 (file)
@@ -1805,10 +1805,12 @@ rspamd_config_add_symbol(struct rspamd_config *cfg,
                                *sym_def->weight_ptr = score;
                                sym_def->score = score;
                                sym_def->priority = priority;
-                               sym_def->flags &= ~RSPAMD_SYMBOL_FLAG_UNSCORED;
+                               sym_def->flags = flags & ~RSPAMD_SYMBOL_FLAG_UNSCORED;
+                       }
+                       else {
+                               /* Preserve UNSCORED flag when not setting a real score */
+                               sym_def->flags = flags | (sym_def->flags & RSPAMD_SYMBOL_FLAG_UNSCORED);
                        }
-
-                       sym_def->flags = flags;
 
                        if (nshots != 0) {
                                sym_def->nshots = nshots;
index b863e11d728e6e48e7fa9928709ef8f79af45e7a..f07010d90f5495f6584ec4051bc3d05ad636aca1 100644 (file)
@@ -2824,7 +2824,7 @@ lua_config_set_metric_symbol(lua_State *L)
        struct rspamd_config *cfg = lua_check_config(L, 1);
        const char *description = NULL,
                           *group = NULL, *name = NULL, *flags_str = NULL;
-       double score;
+       double score = NAN;
        gboolean one_shot = FALSE, one_param = FALSE;
        GError *err = NULL;
        double priority = 0.0;