commit 074033b: [Project] Various fixes for lua_content project
Vsevolod Stakhov
vsevolod at highsecure.ru
Mon Nov 25 13:28:14 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-11-25 13:26:34 +0000
URL: https://github.com/rspamd/rspamd/commit/074033b9aa59529eac839513b982505e6adef7f5 (HEAD -> master)
[Project] Various fixes for lua_content project
---
src/libmime/message.c | 16 +++++++++++-----
src/lua/lua_common.c | 10 ++++++++--
src/lua/lua_mimepart.c | 1 +
test/functional/cases/102_multimap.robot | 8 +++++---
4 files changed, 25 insertions(+), 10 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);
}
diff --git a/test/functional/cases/102_multimap.robot b/test/functional/cases/102_multimap.robot
index c403607fe..c953970dc 100644
--- a/test/functional/cases/102_multimap.robot
+++ b/test/functional/cases/102_multimap.robot
@@ -25,6 +25,10 @@ ${FREEMAIL_CC} ${TESTDIR}/messages/freemailcc.eml
${URL_ICS} ${TESTDIR}/messages/ics.eml
*** Test Cases ***
+URL_ICS
+ ${result} = Scan Message With Rspamc ${URL_ICS}
+ Check Rspamc ${result} Urls: ["test.com"]
+
MAP - DNSBL HIT
${result} = Scan Message With Rspamc ${MESSAGE} -i 127.0.0.2
Check Rspamc ${result} DNSBL_MAP
@@ -327,9 +331,7 @@ FREEMAIL_CC
${result} = Scan Message With Rspamc ${FREEMAIL_CC}
Check Rspamc ${result} FREEMAIL_CC (19.00)[test.com, test1.com, test2.com, test3.com, test4.com, test5.com, test6.com, test7.com, test8.com, test9.com, test10.com, test11.com, test12.com, test13.com, test14.com]
-URL_ICS
- ${result} = Scan Message With Rspamc ${URL_ICS}
- Check Rspamc ${result} Urls: ["test.com"]
+
*** Keywords ***
Multimap Setup
More information about the Commits
mailing list