From: Vsevolod Stakhov Date: Tue, 23 Dec 2025 10:13:43 +0000 (+0000) Subject: [Fix] Restore Lua stack properly in second-pass MIME detection X-Git-Tag: 3.14.3~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77ac680ff0a9ec8a9a9bb66464d82d7a48094b46;p=thirdparty%2Frspamd.git [Fix] Restore Lua stack properly in second-pass MIME detection Fix lua_settop(L, 0) which cleared the entire Lua stack instead of restoring to the previous state, causing segfaults when process_message() was called from Lua unit tests. --- diff --git a/src/libmime/message.c b/src/libmime/message.c index ad2aaf21c3..2bc8fbdedb 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -1637,6 +1637,7 @@ void rspamd_message_process(struct rspamd_task *task) rspamd_mime_parser_get_lua_magic_cbref(task->cfg->mime_parser_cfg) != -1) { unsigned int j; struct rspamd_mime_part *pp; + int second_pass_old_top = lua_gettop(L); PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), j, pp) { gboolean needs_refine = FALSE; @@ -1708,8 +1709,7 @@ void rspamd_message_process(struct rspamd_task *task) else { msg_err_task("second-pass detect type: %s", lua_tostring(L, -1)); } - /* restore stack */ - lua_settop(L, 0); + lua_settop(L, second_pass_old_top); } } }