commit d79e398: [Minor] Some fixes to ids propagation

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Aug 20 16:42:07 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-08-20 17:38:31 +0100
URL: https://github.com/rspamd/rspamd/commit/d79e398a8b089c3268f4aaf3aff12fea888d5264

[Minor] Some fixes to ids propagation

---
 src/libserver/rspamd_symcache.c | 26 +++++++++++++++++++++-----
 src/lua/lua_config.c            | 24 +++++++++++++++++++++++-
 src/plugins/surbl.c             |  4 ++--
 3 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/src/libserver/rspamd_symcache.c b/src/libserver/rspamd_symcache.c
index 900a1894c..69080eb18 100644
--- a/src/libserver/rspamd_symcache.c
+++ b/src/libserver/rspamd_symcache.c
@@ -542,6 +542,8 @@ rspamd_symcache_propagate_dep (struct rspamd_symcache *cache,
 	const guint *ids;
 	guint nids = 0;
 
+	msg_debug_cache ("check id propagation for dependency %s from %s",
+			it->symbol, dit->symbol);
 	ids = rspamd_symcache_get_allowed_settings_ids (cache, dit->symbol, &nids);
 
 	/* TODO: merge? */
@@ -573,12 +575,15 @@ rspamd_symcache_process_dep (struct rspamd_symcache *cache,
 	struct cache_dependency *rdep;
 
 	if (dep->id >= 0) {
+		msg_debug_cache ("process real dependency %s on %s", it->symbol, dep->sym);
 		dit = rspamd_symcache_find_filter (cache, dep->sym, true);
 	}
 
 	if (dep->vid >= 0) {
 		/* Case of the virtual symbol that depends on another (maybe virtual) symbol */
 		vdit = rspamd_symcache_find_filter (cache, dep->sym, false);
+		msg_debug_cache ("process virtual dependency %s(%d) on %s(%d)", it->symbol,
+				dep->vid, vdit->symbol, vdit->id);
 	}
 	else {
 		vdit = dit;
@@ -686,7 +691,8 @@ rspamd_symcache_post_init (struct rspamd_symcache *cache)
 		else {
 			msg_debug_cache ("delayed between %s(%d:%d) -> %s", ddep->from,
 					it->id, vit->id, ddep->to);
-			rspamd_symcache_add_dependency (cache, it->id, ddep->to, vit->id);
+			rspamd_symcache_add_dependency (cache, it->id, ddep->to, vit != it ?
+																	 vit->id : -1);
 		}
 
 		cur = g_list_next (cur);
@@ -730,6 +736,14 @@ rspamd_symcache_post_init (struct rspamd_symcache *cache)
 		}
 	}
 
+	/* Special case for virtual symbols */
+	PTR_ARRAY_FOREACH (cache->virtual, i, it) {
+
+		PTR_ARRAY_FOREACH (it->deps, j, dep) {
+			rspamd_symcache_process_dep (cache, it, dep);
+		}
+	}
+
 	g_ptr_array_sort_with_data (cache->prefilters_empty, prefilters_cmp, cache);
 	g_ptr_array_sort_with_data (cache->prefilters, prefilters_cmp, cache);
 	g_ptr_array_sort_with_data (cache->postfilters, postfilters_cmp, cache);
@@ -2485,7 +2499,7 @@ rspamd_symcache_add_dependency (struct rspamd_symcache *cache,
 
 	g_assert (id_from >= 0 && id_from < (gint)cache->items_by_id->len);
 
-	source = g_ptr_array_index (cache->items_by_id, id_from);
+	source = (struct rspamd_symcache_item *)g_ptr_array_index (cache->items_by_id, id_from);
 	dep = rspamd_mempool_alloc (cache->static_pool, sizeof (*dep));
 	dep->id = id_from;
 	dep->sym = rspamd_mempool_strdup (cache->static_pool, to);
@@ -2494,11 +2508,13 @@ rspamd_symcache_add_dependency (struct rspamd_symcache *cache,
 	dep->vid = -1;
 	g_ptr_array_add (source->deps, dep);
 
-	if (id_from != virtual_id_from) {
+	if (virtual_id_from >= 0) {
+		g_assert (virtual_id_from < (gint)cache->virtual->len);
 		/* We need that for settings id propagation */
-		vsource = g_ptr_array_index (cache->items_by_id, virtual_id_from);
+		vsource = (struct rspamd_symcache_item *)
+				g_ptr_array_index (cache->virtual, virtual_id_from);
 		dep = rspamd_mempool_alloc (cache->static_pool, sizeof (*dep));
-		dep->vid = id_from;
+		dep->vid = virtual_id_from;
 		dep->id = -1;
 		dep->sym = rspamd_mempool_strdup (cache->static_pool, to);
 		/* Will be filled later */
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 9b8c084c0..5c914af79 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -1524,6 +1524,17 @@ rspamd_register_symbol_fromlua (lua_State *L,
 		ids = rspamd_process_id_list (allowed_ids, &nids);
 
 		if (nids > 0) {
+			GString *dbg = g_string_new ("");
+
+			for (guint i = 0; i < nids; i ++) {
+				rspamd_printf_gstring (dbg, "%ud,", ids[i]);
+			}
+
+			dbg->len --;
+
+			msg_debug_config ("allowed ids for %s are: %v", name, dbg);
+			g_string_free (dbg, TRUE);
+
 			rspamd_symcache_set_allowed_settings_ids (cfg->cache, name,
 					ids, nids);
 
@@ -1535,6 +1546,17 @@ rspamd_register_symbol_fromlua (lua_State *L,
 		ids = rspamd_process_id_list (forbidden_ids, &nids);
 
 		if (nids > 0) {
+			GString *dbg = g_string_new ("");
+
+			for (guint i = 0; i < nids; i ++) {
+				rspamd_printf_gstring (dbg, "%ud,", ids[i]);
+			}
+
+			dbg->len --;
+
+			msg_debug_config ("forbidden ids for %s are: %v", name, dbg);
+			g_string_free (dbg, TRUE);
+
 			rspamd_symcache_set_forbidden_settings_ids (cfg->cache, name,
 					ids, nids);
 
@@ -2207,7 +2229,7 @@ lua_config_register_dependency (lua_State * L)
 		if (child_id > 0 && parent != NULL) {
 
 			rspamd_symcache_add_dependency (cfg->cache, child_id, parent,
-					child_id);
+					-1);
 		}
 	}
 	else {
diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c
index 7da36f483..0d03f9516 100644
--- a/src/plugins/surbl.c
+++ b/src/plugins/surbl.c
@@ -868,7 +868,7 @@ surbl_module_parse_rule (const ucl_object_t* value, struct rspamd_config* cfg)
 				1,
 				1);
 		rspamd_symcache_add_dependency (cfg->cache, cb_id,
-				SURBL_REDIRECTOR_CALLBACK, cb_id);
+				SURBL_REDIRECTOR_CALLBACK, -1);
 		/* Failure symbol */
 		g_string_append (sym, "_FAIL");
 		rspamd_symcache_add_symbol (cfg->cache, sym->str,
@@ -1205,7 +1205,7 @@ surbl_module_config (struct rspamd_config *cfg)
 
 		if (cur_suffix->options & SURBL_OPTION_CHECKDKIM) {
 			rspamd_symcache_add_dependency (cfg->cache,
-					cur_suffix->callback_id, "DKIM_TRACE", cur_suffix->callback_id);
+					cur_suffix->callback_id, "DKIM_TRACE", -1);
 		}
 
 		cur_opt = g_list_next (cur_opt);


More information about the Commits mailing list