aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_mimepart.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-04-05 14:50:40 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-04-05 14:50:40 +0100
commit7c4ea9f998b92416e41cad22e8f7f15d9e07be3b (patch)
tree114b66af96b4ead438b62be76c6f01a09352f8cf /src/lua/lua_mimepart.c
parent0d33a57448b61167231b9bf999417a835d69d1bd (diff)
downloadrspamd-7c4ea9f998b92416e41cad22e8f7f15d9e07be3b.tar.gz
rspamd-7c4ea9f998b92416e41cad22e8f7f15d9e07be3b.zip
[Fix] Check return values from Lua functions called from C
Diffstat (limited to 'src/lua/lua_mimepart.c')
-rw-r--r--src/lua/lua_mimepart.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c
index 7f6ede7ef..581a2c260 100644
--- a/src/lua/lua_mimepart.c
+++ b/src/lua/lua_mimepart.c
@@ -935,6 +935,7 @@ lua_mimepart_headers_foreach (lua_State *L)
struct rspamd_lua_regexp *re = NULL;
GList *cur;
struct rspamd_mime_header *hdr;
+ gint old_top;
if (part && lua_isfunction (L, 2)) {
if (lua_istable (L, 3)) {
@@ -981,26 +982,29 @@ lua_mimepart_headers_foreach (lua_State *L)
}
}
+ old_top = lua_gettop (L);
lua_pushvalue (L, 2);
lua_pushstring (L, hdr->name);
rspamd_lua_push_header (L, hdr, full, raw);
- if (lua_pcall (L, 2, 1, 0) != 0) {
+ if (lua_pcall (L, 2, LUA_MULTRET, 0) != 0) {
msg_err ("call to header_foreach failed: %s",
lua_tostring (L, -1));
- lua_pop (L, 1);
+ lua_settop (L, old_top);
break;
}
else {
- if (lua_isboolean (L, -1)) {
- if (lua_toboolean (L, -1)) {
- lua_pop (L, 1);
- break;
+ if (lua_gettop (L) > old_top) {
+ if (lua_isboolean (L, old_top + 1)) {
+ if (lua_toboolean (L, old_top + 1)) {
+ lua_settop (L, old_top);
+ break;
+ }
}
}
}
- lua_pop (L, 1);
+ lua_settop (L, old_top);
cur = g_list_next (cur);
}
}