diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-03-12 16:01:03 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-03-12 16:01:03 -0300 |
| commit | 25da574fcbb68bf507431a6091ab73ac434c9428 (patch) | |
| tree | 6bb694ed0bcd3fea057e90394514320c360bc03c | |
| parent | f5e55be2a0ce64066c1b0554675633b92c91fafb (diff) | |
| download | lua-25da574fcbb68bf507431a6091ab73ac434c9428.tar.gz lua-25da574fcbb68bf507431a6091ab73ac434c9428.tar.bz2 lua-25da574fcbb68bf507431a6091ab73ac434c9428.zip | |
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).
| -rw-r--r-- | ldo.c | 16 | ||||
| -rw-r--r-- | ldo.h | 1 | ||||
| -rw-r--r-- | lstate.c | 2 |
3 files changed, 13 insertions, 6 deletions
| @@ -94,10 +94,6 @@ void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) { | |||
| 94 | setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */ | 94 | setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */ |
| 95 | break; | 95 | break; |
| 96 | } | 96 | } |
| 97 | case LUA_ERRERR: { | ||
| 98 | setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling")); | ||
| 99 | break; | ||
| 100 | } | ||
| 101 | case LUA_OK: { /* special case only for closing upvalues */ | 97 | case LUA_OK: { /* special case only for closing upvalues */ |
| 102 | setnilvalue(s2v(oldtop)); /* no error message */ | 98 | setnilvalue(s2v(oldtop)); /* no error message */ |
| 103 | break; | 99 | break; |
| @@ -199,6 +195,16 @@ static void correctstack (lua_State *L) { | |||
| 199 | /* some space for error handling */ | 195 | /* some space for error handling */ |
| 200 | #define ERRORSTACKSIZE (LUAI_MAXSTACK + 200) | 196 | #define ERRORSTACKSIZE (LUAI_MAXSTACK + 200) |
| 201 | 197 | ||
| 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 | |||
| 202 | /* | 208 | /* |
| 203 | ** Reallocate the stack to a new size, correcting all pointers into it. | 209 | ** Reallocate the stack to a new size, correcting all pointers into it. |
| 204 | ** In ISO C, any pointer use after the pointer has been deallocated is | 210 | ** 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) { | |||
| 248 | a stack error; cannot grow further than that. */ | 254 | a stack error; cannot grow further than that. */ |
| 249 | lua_assert(stacksize(L) == ERRORSTACKSIZE); | 255 | lua_assert(stacksize(L) == ERRORSTACKSIZE); |
| 250 | if (raiseerror) | 256 | if (raiseerror) |
| 251 | luaD_throw(L, LUA_ERRERR); /* error inside message handler */ | 257 | luaD_errerr(L); /* error inside message handler */ |
| 252 | return 0; /* if not 'raiseerror', just signal it */ | 258 | return 0; /* if not 'raiseerror', just signal it */ |
| 253 | } | 259 | } |
| 254 | else if (n < LUAI_MAXSTACK) { /* avoids arithmetic overflows */ | 260 | else if (n < LUAI_MAXSTACK) { /* avoids arithmetic overflows */ |
| @@ -60,6 +60,7 @@ | |||
| 60 | /* type of protected functions, to be ran by 'runprotected' */ | 60 | /* type of protected functions, to be ran by 'runprotected' */ |
| 61 | typedef void (*Pfunc) (lua_State *L, void *ud); | 61 | typedef void (*Pfunc) (lua_State *L, void *ud); |
| 62 | 62 | ||
| 63 | LUAI_FUNC l_noret luaD_errerr (lua_State *L); | ||
| 63 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); | 64 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); |
| 64 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, | 65 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, |
| 65 | const char *mode); | 66 | const char *mode); |
| @@ -166,7 +166,7 @@ void luaE_checkcstack (lua_State *L) { | |||
| 166 | if (getCcalls(L) == LUAI_MAXCCALLS) | 166 | if (getCcalls(L) == LUAI_MAXCCALLS) |
| 167 | luaG_runerror(L, "C stack overflow"); | 167 | luaG_runerror(L, "C stack overflow"); |
| 168 | else if (getCcalls(L) >= (LUAI_MAXCCALLS / 10 * 11)) | 168 | 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 */ |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | 172 | ||
