aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstat
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/libstat
parent0d33a57448b61167231b9bf999417a835d69d1bd (diff)
downloadrspamd-7c4ea9f998b92416e41cad22e8f7f15d9e07be3b.tar.gz
rspamd-7c4ea9f998b92416e41cad22e8f7f15d9e07be3b.zip
[Fix] Check return values from Lua functions called from C
Diffstat (limited to 'src/libstat')
-rw-r--r--src/libstat/stat_process.c71
1 files changed, 40 insertions, 31 deletions
diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c
index 356b53807..0272c8fb7 100644
--- a/src/libstat/stat_process.c
+++ b/src/libstat/stat_process.c
@@ -179,6 +179,9 @@ rspamd_stat_tokenize_parts_metadata (struct rspamd_stat_ctx *st_ctx,
lua_gettable (L, -2);
if (lua_type (L, -1) == LUA_TTABLE) {
+ gint old_top;
+
+ old_top = lua_gettop (L);
lua_pushstring (L, "callback");
lua_gettable (L, -2);
@@ -189,41 +192,47 @@ rspamd_stat_tokenize_parts_metadata (struct rspamd_stat_ctx *st_ctx,
rspamd_lua_setclass (L, "rspamd{task}", -1);
*ptask = task;
- if (lua_pcall (L, 1, 1, 0) != 0) {
+ if (lua_pcall (L, 1, LUA_MULTRET, 0) != 0) {
msg_err_task ("stat_metatokens failed: %s",
lua_tostring (L, -1));
lua_pop (L, 1);
} else {
- /* Iterate over table of tables */
- for (lua_pushnil (L); lua_next (L, -2); lua_pop (L, 1)) {
- elt.flags |= RSPAMD_STAT_TOKEN_FLAG_LUA_META;
-
- if (lua_isnumber (L, -1)) {
- gdouble num = lua_tonumber (L, -1);
- guint8 *pnum = rspamd_mempool_alloc (
- task->task_pool,
- sizeof (num));
-
- msg_debug_task ("got metatoken number: %.2f", num);
- memcpy (pnum, &num, sizeof (num));
- elt.begin = (gchar *) pnum;
- elt.len = sizeof (num);
- g_array_append_val (ar, elt);
- } else if (lua_isstring (L, -1)) {
- const gchar *str;
- gsize tlen;
-
- str = lua_tolstring (L, -1, &tlen);
- guint8 *pstr = rspamd_mempool_alloc (
- task->task_pool,
- tlen);
- memcpy (pstr, str, tlen);
-
- msg_debug_task ("got metatoken string: %*s",
- (gint) tlen, str);
- elt.begin = (gchar *) pstr;
- elt.len = tlen;
- g_array_append_val (ar, elt);
+ if (lua_gettop (L) > old_top &&
+ lua_istable (L, old_top + 1)) {
+ lua_pushvalue (L, old_top + 1);
+ /* Iterate over table of tables */
+ for (lua_pushnil (L); lua_next (L, -2);
+ lua_pop (L, 1)) {
+ elt.flags |= RSPAMD_STAT_TOKEN_FLAG_LUA_META;
+
+ if (lua_isnumber (L, -1)) {
+ gdouble num = lua_tonumber (L, -1);
+ guint8 *pnum = rspamd_mempool_alloc (
+ task->task_pool,
+ sizeof (num));
+
+ msg_debug_task ("got metatoken number: %.2f",
+ num);
+ memcpy (pnum, &num, sizeof (num));
+ elt.begin = (gchar *) pnum;
+ elt.len = sizeof (num);
+ g_array_append_val (ar, elt);
+ } else if (lua_isstring (L, -1)) {
+ const gchar *str;
+ gsize tlen;
+
+ str = lua_tolstring (L, -1, &tlen);
+ guint8 *pstr = rspamd_mempool_alloc (
+ task->task_pool,
+ tlen);
+ memcpy (pstr, str, tlen);
+
+ msg_debug_task ("got metatoken string: %*s",
+ (gint) tlen, str);
+ elt.begin = (gchar *) pstr;
+ elt.len = tlen;
+ g_array_append_val (ar, elt);
+ }
}
}
}