]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Project] Various fixes for lua_content project
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 25 Nov 2019 13:26:34 +0000 (13:26 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 25 Nov 2019 13:26:34 +0000 (13:26 +0000)
src/libmime/message.c
src/lua/lua_common.c
src/lua/lua_mimepart.c
test/functional/cases/102_multimap.robot

index 53c3cce277d3278d042c599e42ed845c86b35716..18eef9f22178ec4da13f89d5737003b3e826bacc 100644 (file)
@@ -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) {
index 2e34c42dd8d45aa37c862e1fce6bde90856cee74..45ca2c97e0576dce2de7bb7bc2a0f0bab8aa92c2 100644 (file)
@@ -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);
 }
index 4de7d83302f5c56ea2d8618fe1c96bc5986f4872..29d3aac500486713cb4dbeff2936ea27268e40ac 100644 (file)
@@ -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);
        }
 
index c403607fe27a33b312c2592afd7322b83633d735..c953970dc025beea338268395547206d0d1b4123 100644 (file)
@@ -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