diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-03-27 17:45:41 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-03-27 17:45:41 +0100 |
commit | c1904b4f751ae59d9a48fab651f4a0e6a232375e (patch) | |
tree | cf2f2bb5259715765784e3379f15952702f05cb7 /src/rspamadm | |
parent | bf2e401ad6246569faff56ec69429451faf7bcbd (diff) | |
download | rspamd-c1904b4f751ae59d9a48fab651f4a0e6a232375e.tar.gz rspamd-c1904b4f751ae59d9a48fab651f4a0e6a232375e.zip |
[Fix] Fix various issues related to Lua stack manipulation
Issue: #841
Diffstat (limited to 'src/rspamadm')
-rw-r--r-- | src/rspamadm/rspamadm.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/rspamadm/rspamadm.c b/src/rspamadm/rspamadm.c index e242ab925..d524a8f61 100644 --- a/src/rspamadm/rspamadm.c +++ b/src/rspamadm/rspamadm.c @@ -190,7 +190,7 @@ rspamadm_execute_lua_ucl_subr (gpointer pL, gint argc, gchar **argv, const ucl_object_t *res, const gchar *script) { lua_State *L = pL; - gint err_idx, cb_idx, i, ret; + gint err_idx, i, ret; GString *tb; g_assert (script != NULL); @@ -203,14 +203,13 @@ rspamadm_execute_lua_ucl_subr (gpointer pL, gint argc, gchar **argv, return FALSE; } else { - if (lua_type (L, -1) == LUA_TFUNCTION) { - cb_idx = luaL_ref (L, LUA_REGISTRYINDEX); - } - else { + if (lua_type (L, -1) != LUA_TFUNCTION) { msg_err ("lua script must return " "function and not %s", lua_typename (L, lua_type (L, -1))); + lua_settop (L, 0); + return FALSE; } } @@ -219,7 +218,7 @@ rspamadm_execute_lua_ucl_subr (gpointer pL, gint argc, gchar **argv, err_idx = lua_gettop (L); /* Push function */ - lua_rawgeti (L, LUA_REGISTRYINDEX, cb_idx); + lua_pushvalue (L, -2); /* Push argv */ lua_newtable (L); @@ -240,15 +239,13 @@ rspamadm_execute_lua_ucl_subr (gpointer pL, gint argc, gchar **argv, g_string_free (tb, TRUE); } - lua_pop (L, 2); + lua_settop (L, 0); return FALSE; } /* error function */ - lua_pop (L, 1); - - luaL_unref (L, LUA_REGISTRYINDEX, cb_idx); + lua_settop (L, 0); return TRUE; } |