commit cdedeb9: fix compatibility with lua-5.4

Tomohiro Tomo-p KATO tomop at teamgedoh.net
Fri Aug 20 17:56:04 UTC 2021


Author: Tomohiro "Tomo-p" KATO
Date: 2021-02-16 00:29:59 +0900
URL: https://github.com/rspamd/rspamd/commit/cdedeb9f4f3168293a1efe0347da753b6f812a5e (refs/pull/3852/head)

fix compatibility with lua-5.4

---
 src/libserver/cfg_rcl.c            | 3 +++
 src/libstat/stat_config.c          | 3 +++
 src/lua/lua_thread_pool.cxx        | 5 ++++-
 src/plugins/fuzzy_check.c          | 3 +++
 src/plugins/lua/hfilter.lua        | 4 ++--
 src/plugins/lua/milter_headers.lua | 2 +-
 6 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index b19a1dedc..d91ebf3ae 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -3571,6 +3571,9 @@ rspamd_rcl_maybe_apply_lua_transform (struct rspamd_config *cfg)
 		return;
 	}
 	else {
+#if LUA_VERSION_NUM >= 504
+		lua_settop(L, -2);
+#endif
 		if (lua_type (L, -1) != LUA_TFUNCTION) {
 			msg_warn_config ("lua script must return "
 					"function and not %s",
diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c
index 17d0fdcc7..0c9ae2ed0 100644
--- a/src/libstat/stat_config.c
+++ b/src/libstat/stat_config.c
@@ -172,6 +172,9 @@ rspamd_stat_init (struct rspamd_config *cfg, struct ev_loop *ev_base)
 				lua_tostring (L, -1));
 	}
 	else {
+#if LUA_VERSION_NUM >= 504
+		lua_settop(L, -2);
+#endif
 		if (lua_type (L, -1) != LUA_TTABLE) {
 			msg_err_config ("lua stat must return "
 							"table and not %s",
diff --git a/src/lua/lua_thread_pool.cxx b/src/lua/lua_thread_pool.cxx
index 62da49482..dc6c15163 100644
--- a/src/lua/lua_thread_pool.cxx
+++ b/src/lua/lua_thread_pool.cxx
@@ -261,12 +261,15 @@ lua_thread_pool_restore_callback_full(struct lua_callback_state *cbs,
 
 static gint
 lua_do_resume_full(lua_State *L, gint narg, const gchar *loc) {
+#if LUA_VERSION_NUM >= 504
+	int nres;
+#endif
 	msg_debug_lua_threads ("%s: lua_do_resume_full", loc);
 #if LUA_VERSION_NUM < 502
 	return lua_resume(L, narg);
 #else
 #if LUA_VERSION_NUM >= 504
-	return lua_resume (L, NULL, narg, NULL);
+	return lua_resume (L, NULL, narg, &nres);
 #else
 	return lua_resume (L, NULL, narg);
 #endif
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c
index 722daeacb..ea8bcf756 100644
--- a/src/plugins/fuzzy_check.c
+++ b/src/plugins/fuzzy_check.c
@@ -1006,6 +1006,9 @@ fuzzy_check_module_config (struct rspamd_config *cfg, bool validate)
 		fuzzy_module_ctx->enabled = FALSE;
 	}
 	else {
+#if LUA_VERSION_NUM >= 504
+		lua_settop(L, -2);
+#endif
 		if (lua_type (L, -1) != LUA_TTABLE) {
 			msg_err_config ("lua fuzzy must return "
 							"table and not %s",
diff --git a/src/plugins/lua/hfilter.lua b/src/plugins/lua/hfilter.lua
index 9179f63b8..3889eaa5b 100644
--- a/src/plugins/lua/hfilter.lua
+++ b/src/plugins/lua/hfilter.lua
@@ -357,7 +357,7 @@ local function hfilter_callback(task)
               local lines =  html_text_part:get_lines_count()
               if lines > 0 and lines < 2 then
                 task:insert_result('HFILTER_URL_ONELINE', 1.00,
-                  string.format('html:%d:%d', sc, lines))
+                  string.format('html:%d:%d', math.floor(sc), lines))
               end
             end
           end
@@ -376,7 +376,7 @@ local function hfilter_callback(task)
             local lines = plain_text_part:get_lines_count()
             if lines > 0 and lines < 2 then
               task:insert_result('HFILTER_URL_ONELINE', 1.00,
-                string.format('plain:%d:%d', rel, lines))
+                string.format('plain:%d:%d', math.floor(rel), lines))
             end
           end
         end
diff --git a/src/plugins/lua/milter_headers.lua b/src/plugins/lua/milter_headers.lua
index 0dfaa9e03..1b58cee86 100644
--- a/src/plugins/lua/milter_headers.lua
+++ b/src/plugins/lua/milter_headers.lua
@@ -383,7 +383,7 @@ local function milter_headers(task)
     if local_mod.remove then
       remove[local_mod.header] = local_mod.remove
     end
-    add[local_mod.header] = string.rep(local_mod.char, score)
+    add[local_mod.header] = string.rep(local_mod.char, math.floor(score))
   end
 
   local function spam_header (class, name, value, remove_v)


More information about the Commits mailing list