Skip to content

Commit 25da574

Browse files
committed
Bug: 'luaD_seterrorobj' should not raise errors
This function can be called unprotected, so it should not raise any kind of errors. (It could raise a memory-allocation error when creating a message).
1 parent f5e55be commit 25da574

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

ldo.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {
9494
setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */
9595
break;
9696
}
97-
case LUA_ERRERR: {
98-
setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling"));
99-
break;
100-
}
10197
case LUA_OK: { /* special case only for closing upvalues */
10298
setnilvalue(s2v(oldtop)); /* no error message */
10399
break;
@@ -199,6 +195,16 @@ static void correctstack (lua_State *L) {
199195
/* some space for error handling */
200196
#define ERRORSTACKSIZE (LUAI_MAXSTACK + 200)
201197

198+
199+
/* raise an error while running the message handler */
200+
l_noret luaD_errerr (lua_State *L) {
201+
TString *msg = luaS_newliteral(L, "error in error handling");
202+
setsvalue2s(L, L->top.p, msg);
203+
L->top.p++; /* assume EXTRA_STACK */
204+
luaD_throw(L, LUA_ERRERR);
205+
}
206+
207+
202208
/*
203209
** Reallocate the stack to a new size, correcting all pointers into it.
204210
** In ISO C, any pointer use after the pointer has been deallocated is
@@ -248,7 +254,7 @@ int luaD_growstack (lua_State *L, int n, int raiseerror) {
248254
a stack error; cannot grow further than that. */
249255
lua_assert(stacksize(L) == ERRORSTACKSIZE);
250256
if (raiseerror)
251-
luaD_throw(L, LUA_ERRERR); /* error inside message handler */
257+
luaD_errerr(L); /* error inside message handler */
252258
return 0; /* if not 'raiseerror', just signal it */
253259
}
254260
else if (n < LUAI_MAXSTACK) { /* avoids arithmetic overflows */

ldo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
/* type of protected functions, to be ran by 'runprotected' */
6161
typedef void (*Pfunc) (lua_State *L, void *ud);
6262

63+
LUAI_FUNC l_noret luaD_errerr (lua_State *L);
6364
LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
6465
LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
6566
const char *mode);

lstate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void luaE_checkcstack (lua_State *L) {
166166
if (getCcalls(L) == LUAI_MAXCCALLS)
167167
luaG_runerror(L, "C stack overflow");
168168
else if (getCcalls(L) >= (LUAI_MAXCCALLS / 10 * 11))
169-
luaD_throw(L, LUA_ERRERR); /* error while handling stack error */
169+
luaD_errerr(L); /* error while handling stack error */
170170
}
171171

172172

0 commit comments

Comments
 (0)