commit 08a71f0: [Fix] Spamassassin: Preserve 'pcre_only' flag when dealing with regexp replacements

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Nov 23 20:14:06 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-11-23 20:07:57 +0000
URL: https://github.com/rspamd/rspamd/commit/08a71f0108cbd92c750924f91d3522364b30e66a (HEAD -> master)

[Fix] Spamassassin: Preserve 'pcre_only' flag when dealing with regexp replacements

---
 src/lua/lua_config.c             | 16 +++++++++++++---
 src/plugins/lua/spamassassin.lua |  3 ++-
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index f3dc414db..836654500 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -3072,20 +3072,30 @@ lua_config_replace_regexp (lua_State *L)
 	LUA_TRACE_POINT;
 	struct rspamd_config *cfg = lua_check_config (L, 1);
 	struct rspamd_lua_regexp *old_re = NULL, *new_re = NULL;
+	gboolean pcre_only = FALSE;
 	GError *err = NULL;
 
 	if (cfg != NULL) {
 		if (!rspamd_lua_parse_table_arguments (L, 2, &err,
 				RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT,
-				"*old_re=U{regexp};*new_re=U{regexp}",
-				&old_re, &new_re)) {
-			msg_err_config ("cannot get parameters list: %e", err);
+				"*old_re=U{regexp};*new_re=U{regexp};pcre_only=B",
+				&old_re, &new_re, &pcre_only)) {
+			gint ret = luaL_error (L, "cannot get parameters list: %s",
+					err ? err->message : "invalid arguments");
 
 			if (err) {
 				g_error_free (err);
 			}
+
+			return ret;
 		}
 		else {
+
+			if (pcre_only) {
+				rspamd_regexp_set_flags (new_re->re,
+						rspamd_regexp_get_flags (new_re->re) | RSPAMD_REGEXP_FLAG_PCRE_ONLY);
+			}
+
 			rspamd_re_cache_replace (cfg->re_cache, old_re->re, new_re->re);
 		}
 	}
diff --git a/src/plugins/lua/spamassassin.lua b/src/plugins/lua/spamassassin.lua
index 691930bb1..2b0e5e44e 100644
--- a/src/plugins/lua/spamassassin.lua
+++ b/src/plugins/lua/spamassassin.lua
@@ -1240,7 +1240,8 @@ local function post_process()
           lua_util.debugm(N, rspamd_config, 'replace %1 -> %2', r, nexpr)
           rspamd_config:replace_regexp({
             old_re = rule['re'],
-            new_re = nre
+            new_re = nre,
+            pcre_only = is_pcre_only(rule['symbol']),
           })
           rule['re'] = nre
           rule['re_expr'] = nexpr


More information about the Commits mailing list