From 42d40581dd919fb134c07027ca1ce0844c670daf Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 20 May 2022 13:14:33 -0300 Subject: Save stack space while handling errors Because error handling (luaG_errormsg) uses slots from EXTRA_STACK, and some errors can recur (e.g., string overflow while creating an error message in 'luaG_runerror', or a C-stack overflow before calling the message handler), the code should use stack slots with parsimony. This commit fixes the bug "Lua-stack overflow when C stack overflows while handling an error". --- ldebug.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'ldebug.c') diff --git a/ldebug.c b/ldebug.c index a716d95e..fa15eaf6 100644 --- a/ldebug.c +++ b/ldebug.c @@ -824,8 +824,11 @@ l_noret luaG_runerror (lua_State *L, const char *fmt, ...) { va_start(argp, fmt); msg = luaO_pushvfstring(L, fmt, argp); /* format message */ va_end(argp); - if (isLua(ci)) /* if Lua function, add source:line information */ + if (isLua(ci)) { /* if Lua function, add source:line information */ luaG_addinfo(L, msg, ci_func(ci)->p->source, getcurrentline(ci)); + setobjs2s(L, L->top - 2, L->top - 1); /* remove 'msg' from the stack */ + L->top--; + } luaG_errormsg(L); } -- cgit v1.2.3-55-g6feb