]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Add a concept of ignored symbols to avoid race conditions
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 22 Jun 2018 15:28:52 +0000 (16:28 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 22 Jun 2018 15:28:52 +0000 (16:28 +0100)
src/libmime/filter.h
src/libserver/composites.c
src/libserver/protocol.c
src/libserver/roll_history.c
src/libserver/task.c
src/lua/lua_task.c

index 798e5305f29ffe61e4988db675816b9d132f13b3..8d90ef87aa27e236a4205b2e92e270d7f870160a 100644 (file)
@@ -19,6 +19,11 @@ struct rspamd_symbol_option {
        struct rspamd_symbol_option *prev, *next;
 };
 
+enum rspamd_symbol_result_flags {
+       RSPAMD_SYMBOL_RESULT_NORMAL = 0,
+       RSPAMD_SYMBOL_RESULT_IGNORED = (1 << 0)
+};
+
 /**
  * Rspamd symbol
  */
@@ -29,6 +34,7 @@ struct rspamd_symbol_result {
        const gchar *name;
        struct rspamd_symbol *sym;                                              /**< symbol configuration                                       */
        guint nshots;
+       enum rspamd_symbol_result_flags flags;
 };
 
 /**
index 67ed71149f7b9da65efacb1836ed7304bbc3fea2..2ac8209905eefac92d1910703260fa89564a9d15 100644 (file)
@@ -424,7 +424,7 @@ composites_remove_symbols (gpointer key, gpointer value, gpointer data)
 
        if (has_valid_op) {
                if (want_remove_symbol || want_forced) {
-                       g_hash_table_remove (cd->metric_res->symbols, key);
+                       rd->ms->flags |= RSPAMD_SYMBOL_RESULT_IGNORED;
                        msg_debug_composites ("remove symbol %s", key);
                }
 
index 51b2fa0e5bdd3920c65ab2fe64849b50bc18ec47..0e4f9cb0c9fc7cecd5c4bc19a86518923f45c3ff 100644 (file)
@@ -970,8 +970,10 @@ rspamd_metric_result_ucl (struct rspamd_task *task,
 
        while (g_hash_table_iter_next (&hiter, &h, &v)) {
                sym = (struct rspamd_symbol_result *)v;
-               sobj = rspamd_metric_symbol_ucl (task, sym);
-               ucl_object_insert_key (obj, sobj, h, 0, false);
+               if (!(sym->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) {
+                       sobj = rspamd_metric_symbol_ucl (task, sym);
+                       ucl_object_insert_key (obj, sobj, h, 0, false);
+               }
        }
 
        if (task->cmd == CMD_CHECK_V2) {
index 04f2da0c68daa99df760c50fcf739341df178df8..6dbd4d338aa7fd2f30c4049ef81fcebf35552327 100644 (file)
@@ -77,6 +77,10 @@ roll_history_symbols_callback (gpointer key, gpointer value, void *user_data)
        struct rspamd_symbol_result *s = value;
        guint wr;
 
+       if (s->flags & RSPAMD_SYMBOL_RESULT_IGNORED) {
+               return;
+       }
+
        if (cb->remain > 0) {
                wr = rspamd_snprintf (cb->pos, cb->remain, "%s, ", s->name);
                cb->pos += wr;
index f626a8c7b445202bab5f650758262d9339550dd1..d881c68974b9a1138680297be9a1507aa5380ab2 100644 (file)
@@ -1087,7 +1087,11 @@ rspamd_task_log_metric_res (struct rspamd_task *task,
                        sorted_symbols = g_ptr_array_sized_new (g_hash_table_size (mres->symbols));
 
                        while (g_hash_table_iter_next (&it, &k, &v)) {
-                               g_ptr_array_add (sorted_symbols, v);
+                               sym = v;
+
+                               if (!(sym->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) {
+                                       g_ptr_array_add (sorted_symbols, v);
+                               }
                        }
 
                        g_ptr_array_sort (sorted_symbols, rspamd_task_compare_log_sym);
index ca55609a7de782afc2de0e918c84d880086e6d1e..db5bd090a9a0e5d834fd693097c8225f986898a9 100644 (file)
@@ -3309,11 +3309,13 @@ lua_task_get_symbols (lua_State *L)
 
                        while (g_hash_table_iter_next (&it, &k, &v)) {
                                s = v;
-                               lua_pushstring (L, k);
-                               lua_rawseti (L, -3, i);
-                               lua_pushnumber (L, s->score);
-                               lua_rawseti (L, -2, i);
-                               i ++;
+                               if (!(s->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) {
+                                       lua_pushstring (L, k);
+                                       lua_rawseti (L, -3, i);
+                                       lua_pushnumber (L, s->score);
+                                       lua_rawseti (L, -2, i);
+                                       i++;
+                               }
                        }
                }
                else {
@@ -3384,14 +3386,17 @@ lua_task_get_symbols_numeric (lua_State *L)
                        g_hash_table_iter_init (&it, mres->symbols);
 
                        while (g_hash_table_iter_next (&it, &k, &v)) {
-                               id = rspamd_symbols_cache_find_symbol (task->cfg->cache,
-                                               k);
                                s = v;
-                               lua_pushnumber (L, id);
-                               lua_rawseti (L, -3, i);
-                               lua_pushnumber (L, s->score);
-                               lua_rawseti (L, -2, i);
-                               i ++;
+
+                               if (!(s->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) {
+                                       id = rspamd_symbols_cache_find_symbol (task->cfg->cache,
+                                                       k);
+                                       lua_pushnumber (L, id);
+                                       lua_rawseti (L, -3, i);
+                                       lua_pushnumber (L, s->score);
+                                       lua_rawseti (L, -2, i);
+                                       i++;
+                               }
                        }
                }
                else {