aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-03-12 12:27:40 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-03-12 12:28:19 +0000
commita95dc640f911d913224fa7564c1d470325c11f9a (patch)
tree5752ad4c74969f33a14e26ba61bd7e230491257a
parent12d5f4a6ec4798d5e91cc81ef2db605d8a0ab855 (diff)
downloadrspamd-a95dc640f911d913224fa7564c1d470325c11f9a.tar.gz
rspamd-a95dc640f911d913224fa7564c1d470325c11f9a.zip
[Fix] Fix lua symbols scores registration when config does not define scores
-rw-r--r--src/libserver/cfg_file.h1
-rw-r--r--src/libserver/cfg_utils.c5
-rw-r--r--src/lua/lua_config.c19
3 files changed, 17 insertions, 8 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index b368464a0..702325f62 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -130,6 +130,7 @@ enum rspamd_symbol_flags {
RSPAMD_SYMBOL_FLAG_ONEPARAM = (1 << 2),
RSPAMD_SYMBOL_FLAG_UNGROUPPED = (1 << 3),
RSPAMD_SYMBOL_FLAG_DISABLED = (1 << 4),
+ RSPAMD_SYMBOL_FLAG_UNSCORED = (1 << 5),
};
/**
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index 9a308a8a4..8486a029f 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -1625,6 +1625,7 @@ rspamd_config_new_symbol (struct rspamd_config *cfg, const gchar *symbol,
score = 0.0;
/* Also set priority to 0 to allow override by anything */
sym_def->priority = 0;
+ flags |= RSPAMD_SYMBOL_FLAG_UNSCORED;
}
else {
sym_def->priority = priority;
@@ -1725,7 +1726,8 @@ rspamd_config_add_symbol (struct rspamd_config *cfg,
}
}
- if (sym_def->priority > priority) {
+ if (sym_def->priority > priority &&
+ (isnan(score) || !(sym_def->flags & RSPAMD_SYMBOL_FLAG_UNSCORED))) {
msg_debug_config ("symbol %s has been already registered with "
"priority %ud, do not override (new priority: %ud)",
symbol,
@@ -1759,6 +1761,7 @@ 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;
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 8afe8fbfe..fbaadd8bb 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -2049,7 +2049,7 @@ lua_config_register_symbol (lua_State * L)
}
else {
rspamd_config_add_symbol (cfg, name,
- 0.0, description, group, flags,
+ NAN, description, group, flags,
0, nshots);
}
@@ -2314,7 +2314,7 @@ lua_config_set_metric_symbol (lua_State * L)
struct rspamd_config *cfg = lua_check_config (L, 1);
const gchar *description = NULL,
*group = NULL, *name = NULL, *flags_str = NULL;
- double weight;
+ double score;
gboolean one_shot = FALSE, one_param = FALSE;
GError *err = NULL;
gdouble priority = 0.0;
@@ -2329,7 +2329,7 @@ lua_config_set_metric_symbol (lua_State * L)
"*name=S;score=N;description=S;"
"group=S;one_shot=B;one_param=B;priority=N;flags=S;"
"nshots=I",
- &name, &weight, &description,
+ &name, &score, &description,
&group, &one_shot, &one_param,
&priority, &flags_str, &nshots)) {
msg_err_config ("bad arguments: %e", err);
@@ -2340,7 +2340,7 @@ lua_config_set_metric_symbol (lua_State * L)
}
else {
name = luaL_checkstring (L, 2);
- weight = luaL_checknumber (L, 3);
+ score = luaL_checknumber (L, 3);
if (lua_gettop (L) > 3 && lua_type (L, 4) == LUA_TSTRING) {
description = luaL_checkstring (L, 4);
@@ -2380,7 +2380,7 @@ lua_config_set_metric_symbol (lua_State * L)
}
rspamd_config_add_symbol (cfg, name,
- weight, description, group, flags, (guint) priority, nshots);
+ score, description, group, flags, (guint) priority, nshots);
if (lua_type (L, 2) == LUA_TTABLE) {
@@ -2786,7 +2786,8 @@ lua_config_newindex (lua_State *L)
* Now check if a symbol has not been registered in any metric and
* insert default value if applicable
*/
- if (g_hash_table_lookup (cfg->symbols, name) == NULL) {
+ struct rspamd_symbol *sym = g_hash_table_lookup (cfg->symbols, name);
+ if (sym == NULL || (sym->flags & RSPAMD_SYMBOL_FLAG_UNSCORED)) {
nshots = cfg->default_max_shots;
lua_pushstring (L, "score");
@@ -2794,6 +2795,10 @@ lua_config_newindex (lua_State *L)
if (lua_type (L, -1) == LUA_TNUMBER) {
score = lua_tonumber (L, -1);
+ if (sym) {
+ /* Reset unscored flag */
+ sym->flags &= ~RSPAMD_SYMBOL_FLAG_UNSCORED;
+ }
}
lua_pop (L, 1);
@@ -2843,7 +2848,7 @@ lua_config_newindex (lua_State *L)
}
else if (group) {
/* Add with zero score */
- rspamd_config_add_symbol (cfg, name, 0.0,
+ rspamd_config_add_symbol (cfg, name, NAN,
description, group, flags, 0, nshots);
}