commit 46f7de9: [Test] Fix using of Lua functions when called from Lua

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Sep 9 16:42:04 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-09-09 17:40:26 +0100
URL: https://github.com/rspamd/rspamd/commit/46f7de90948da42cbeccc4b85ab2f843b2aa7ab3 (HEAD -> master)

[Test] Fix using of Lua functions when called from Lua

---
 src/libmime/message.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/libmime/message.c b/src/libmime/message.c
index 9ea4f194f..0f260d726 100644
--- a/src/libmime/message.c
+++ b/src/libmime/message.c
@@ -1361,13 +1361,17 @@ rspamd_message_process (struct rspamd_task *task)
 	gdouble diff, *pdiff;
 	guint tw, *ptw, dw;
 	struct rspamd_mime_part *part;
-	lua_State *L = task->cfg->lua_state;
+	lua_State *L = NULL;
 	gint func_pos = -1;
 
+	if (task->cfg) {
+		L = task->cfg->lua_state;
+	}
+
 	rspamd_images_process (task);
 	rspamd_archives_process (task);
 
-	if (rspamd_lua_require_function (L,
+	if (L && rspamd_lua_require_function (L,
 			"lua_magic", "detect_mime_part")) {
 		func_pos = lua_gettop (L);
 	}
@@ -1434,7 +1438,9 @@ rspamd_message_process (struct rspamd_task *task)
 		rspamd_message_process_text_part_maybe (task, part);
 	}
 
-	lua_settop (L, 0);
+	if (func_pos != -1) {
+		lua_settop (L, func_pos - 1);
+	}
 
 	/* Calculate average words length and number of short words */
 	struct rspamd_mime_text_part *text_part;


More information about the Commits mailing list