]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Restore Lua stack properly in second-pass MIME detection
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 23 Dec 2025 10:13:43 +0000 (10:13 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 23 Dec 2025 10:13:43 +0000 (10:13 +0000)
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.

src/libmime/message.c

index ad2aaf21c326d5a5ed49dfdc9065eeffc0c3e403..2bc8fbdedb112b44c788b45612c3945e5baa73ca 100644 (file)
@@ -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);
                        }
                }
        }