summaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-09-04 17:16:24 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-09-04 17:16:24 +0100
commit4f4d0c8e3a3be7952a9ec4b11c699e4512172345 (patch)
tree3137c396629b8b0f383f35214695fae728e8ddfa /src/lua
parent35904c44e0e31116a7c4c8a06ea09381866b510f (diff)
downloadrspamd-4f4d0c8e3a3be7952a9ec4b11c699e4512172345.tar.gz
rspamd-4f4d0c8e3a3be7952a9ec4b11c699e4512172345.zip
[Fix] Fix lua stack corruption when logging large tables
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_logger.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/lua/lua_logger.c b/src/lua/lua_logger.c
index 6d0075c99..f4f8f3dbf 100644
--- a/src/lua/lua_logger.c
+++ b/src/lua/lua_logger.c
@@ -460,12 +460,12 @@ lua_logger_out_userdata(lua_State *L, gint pos, gchar *outbuf, gsize len,
return r;
}
-#define MOVE_BUF(d, remain, r) \
- (d) += (r); \
- (remain) -= (r); \
- if ((remain) == 0) { \
- lua_pop(L, 1); \
- break; \
+#define MOVE_BUF(d, remain, r) \
+ (d) += (r); \
+ (remain) -= (r); \
+ if ((remain) == 0) { \
+ lua_settop(L, old_top); \
+ break; \
}
static gsize
@@ -477,12 +477,13 @@ lua_logger_out_table(lua_State *L, gint pos, gchar *outbuf, gsize len,
gsize remain = len, r;
gboolean first = TRUE;
gconstpointer self = NULL;
- gint i, tpos, last_seq = -1;
+ gint i, tpos, last_seq = -1, old_top;
if (!lua_istable(L, pos) || remain == 0) {
return 0;
}
+ old_top = lua_gettop(L);
self = lua_topointer(L, pos);
/* Check if we have seen this pointer */
@@ -538,7 +539,6 @@ lua_logger_out_table(lua_State *L, gint pos, gchar *outbuf, gsize len,
/* Get string keys (pairs) */
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
/* 'key' is at index -2 and 'value' is at index -1 */
-
if (lua_type(L, -2) == LUA_TNUMBER) {
if (last_seq > 0) {
lua_pushvalue(L, -2);
@@ -577,7 +577,7 @@ lua_logger_out_table(lua_State *L, gint pos, gchar *outbuf, gsize len,
first = FALSE;
}
- lua_pop(L, 1);
+ lua_settop(L, old_top);
r = rspamd_snprintf(d, remain + 1, "}");
d += r;