diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-11-25 13:26:34 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-11-25 13:26:34 +0000 |
commit | 074033b9aa59529eac839513b982505e6adef7f5 (patch) | |
tree | ca193c994d6fbe264f7763850895171486bd182b /src | |
parent | 82d8d983b1f1a2f53daea13325690651086f2c82 (diff) | |
download | rspamd-074033b9aa59529eac839513b982505e6adef7f5.tar.gz rspamd-074033b9aa59529eac839513b982505e6adef7f5.zip |
[Project] Various fixes for lua_content project
Diffstat (limited to 'src')
-rw-r--r-- | src/libmime/message.c | 16 | ||||
-rw-r--r-- | src/lua/lua_common.c | 10 | ||||
-rw-r--r-- | src/lua/lua_mimepart.c | 1 |
3 files changed, 20 insertions, 7 deletions
diff --git a/src/libmime/message.c b/src/libmime/message.c index 53c3cce27..18eef9f22 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -1315,7 +1315,7 @@ rspamd_message_process (struct rspamd_task *task) guint tw, *ptw, dw; struct rspamd_mime_part *part; lua_State *L = NULL; - gint magic_func_pos = -1, content_func_pos = -1, old_top = -1; + gint magic_func_pos = -1, content_func_pos = -1, old_top = -1, funcs_top = -1; if (task->cfg) { L = task->cfg->lua_state; @@ -1343,11 +1343,15 @@ rspamd_message_process (struct rspamd_task *task) msg_err_task ("cannot require lua_content.maybe_process_mime_part"); } + funcs_top = lua_gettop (L); + PTR_ARRAY_FOREACH (MESSAGE_FIELD (task, parts), i, part) { if (magic_func_pos != -1 && part->parsed_data.len > 0) { struct rspamd_mime_part **pmime; struct rspamd_task **ptask; + lua_pushcfunction (L, &rspamd_lua_traceback); + gint err_idx = lua_gettop (L); lua_pushvalue (L, magic_func_pos); pmime = lua_newuserdata (L, sizeof (struct rspamd_mime_part *)); rspamd_lua_setclass (L, "rspamd{mimepart}", -1); @@ -1356,7 +1360,7 @@ rspamd_message_process (struct rspamd_task *task) rspamd_lua_setclass (L, "rspamd{task}", -1); *ptask = task; - if (lua_pcall (L, 2, 2, 0) != 0) { + if (lua_pcall (L, 2, 2, err_idx) != 0) { msg_err_task ("cannot detect type: %s", lua_tostring (L, -1)); } else { @@ -1396,7 +1400,7 @@ rspamd_message_process (struct rspamd_task *task) } } - lua_settop (L, magic_func_pos); + lua_settop (L, funcs_top); } /* Now detect content */ @@ -1404,6 +1408,8 @@ rspamd_message_process (struct rspamd_task *task) struct rspamd_mime_part **pmime; struct rspamd_task **ptask; + lua_pushcfunction (L, &rspamd_lua_traceback); + gint err_idx = lua_gettop (L); lua_pushvalue (L, content_func_pos); pmime = lua_newuserdata (L, sizeof (struct rspamd_mime_part *)); rspamd_lua_setclass (L, "rspamd{mimepart}", -1); @@ -1412,11 +1418,11 @@ rspamd_message_process (struct rspamd_task *task) rspamd_lua_setclass (L, "rspamd{task}", -1); *ptask = task; - if (lua_pcall (L, 2, 2, 0) != 0) { + if (lua_pcall (L, 2, 0, err_idx) != 0) { msg_err_task ("cannot detect content: %s", lua_tostring (L, -1)); } - lua_settop (L, magic_func_pos); + lua_settop (L, funcs_top); } if (part->part_type == RSPAMD_MIME_PART_UNDEFINED) { diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 2e34c42dd..45ca2c97e 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -1829,8 +1829,14 @@ rspamd_lua_get_traceback_string (lua_State *L, luaL_Buffer *buf) { const gchar *msg = lua_tostring (L, -1); - luaL_addstring (buf, msg); - lua_pop (L, 1); /* Error string */ + if (msg) { + luaL_addstring (buf, msg); + lua_pop (L, 1); /* Error string */ + } + else { + luaL_addstring (buf, "unknown error"); + } + luaL_addstring (buf, "; trace:"); rspamd_lua_traceback_string (L, buf); } diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c index 4de7d8330..29d3aac50 100644 --- a/src/lua/lua_mimepart.c +++ b/src/lua/lua_mimepart.c @@ -2106,6 +2106,7 @@ lua_mimepart_set_specific (lua_State * L) luaL_unref (L, LUA_REGISTRYINDEX, part->specific.lua_specific.cbref); } else { + part->part_type = RSPAMD_MIME_PART_CUSTOM_LUA; lua_pushnil (L); } |