diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-03-22 15:04:29 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-03-22 15:32:33 +0000 |
commit | c9e0716e3e736c22a966a954ba2429eebda96a0a (patch) | |
tree | b34616095342c1be48c240b2b503b2386bd91ded /src/lua/lua_tcp.c | |
parent | 5fada4c4ad1f6b87a356d829677c73f61c18e7dc (diff) | |
download | rspamd-c9e0716e3e736c22a966a954ba2429eebda96a0a.tar.gz rspamd-c9e0716e3e736c22a966a954ba2429eebda96a0a.zip |
[Fix] Try to fix various Lua stack issues
Diffstat (limited to 'src/lua/lua_tcp.c')
-rw-r--r-- | src/lua/lua_tcp.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c index dcaa3bc57..3bfadf8cb 100644 --- a/src/lua/lua_tcp.c +++ b/src/lua/lua_tcp.c @@ -323,6 +323,12 @@ lua_tcp_maybe_free (struct lua_tcp_cbdata *cbd) } } +#ifdef __GNUC__ +static void +lua_tcp_push_error (struct lua_tcp_cbdata *cbd, gboolean is_fatal, + const char *err, ...) __attribute__ ((format(printf, 3, 4))); +#endif + static void lua_tcp_push_error (struct lua_tcp_cbdata *cbd, gboolean is_fatal, const char *err, ...) @@ -330,7 +336,7 @@ lua_tcp_push_error (struct lua_tcp_cbdata *cbd, gboolean is_fatal, va_list ap, ap_copy; struct lua_tcp_cbdata **pcbd; struct lua_tcp_handler *hdl; - gint cbref; + gint cbref, top; va_start (ap, err); @@ -338,7 +344,6 @@ lua_tcp_push_error (struct lua_tcp_cbdata *cbd, gboolean is_fatal, hdl = g_queue_peek_head (cbd->handlers); if (hdl == NULL) { - va_end (ap_copy); break; } @@ -350,6 +355,7 @@ lua_tcp_push_error (struct lua_tcp_cbdata *cbd, gboolean is_fatal, } if (cbref != -1) { + top = lua_gettop (cbd->L); lua_rawgeti (cbd->L, LUA_REGISTRYINDEX, cbref); /* Error message */ @@ -367,9 +373,10 @@ lua_tcp_push_error (struct lua_tcp_cbdata *cbd, gboolean is_fatal, if (lua_pcall (cbd->L, 3, 0, 0) != 0) { msg_info ("callback call failed: %s", lua_tostring (cbd->L, -1)); - lua_pop (cbd->L, 1); } + lua_settop (cbd->L, top); + REF_RELEASE (cbd); } @@ -391,7 +398,7 @@ lua_tcp_push_data (struct lua_tcp_cbdata *cbd, const guint8 *str, gsize len) struct rspamd_lua_text *t; struct lua_tcp_cbdata **pcbd; struct lua_tcp_handler *hdl; - gint cbref, arg_cnt; + gint cbref, arg_cnt, top; hdl = g_queue_peek_head (cbd->handlers); @@ -405,6 +412,7 @@ lua_tcp_push_data (struct lua_tcp_cbdata *cbd, const guint8 *str, gsize len) } if (cbref != -1) { + top = lua_gettop (cbd->L); lua_rawgeti (cbd->L, LUA_REGISTRYINDEX, cbref); /* Error */ lua_pushnil (cbd->L); @@ -430,9 +438,9 @@ lua_tcp_push_data (struct lua_tcp_cbdata *cbd, const guint8 *str, gsize len) if (lua_pcall (cbd->L, arg_cnt, 0, 0) != 0) { msg_info ("callback call failed: %s", lua_tostring (cbd->L, -1)); - lua_pop (cbd->L, 1); } + lua_settop (cbd->L, top); REF_RELEASE (cbd); } } @@ -686,7 +694,9 @@ lua_tcp_handler (int fd, short what, gpointer ud) if (cbd->connect_cb != -1) { struct lua_tcp_cbdata **pcbd; + gint top; + top = lua_gettop (cbd->L); lua_rawgeti (cbd->L, LUA_REGISTRYINDEX, cbd->connect_cb); pcbd = lua_newuserdata (cbd->L, sizeof (*pcbd)); *pcbd = cbd; @@ -695,9 +705,10 @@ lua_tcp_handler (int fd, short what, gpointer ud) if (lua_pcall (cbd->L, 1, 0, 0) != 0) { msg_info ("callback call failed: %s", lua_tostring (cbd->L, -1)); - lua_pop (cbd->L, 1); } + lua_settop (cbd->L, top); + REF_RELEASE (cbd); } } |