aboutsummaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-11-24 16:08:55 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-11-24 16:08:55 -0300
commit842a83f09caa2ebd4bc03e0076420148ac07c808 (patch)
tree92eca69ee75b32156b14c1a9d0b5a31f16ef9118 /lauxlib.c
parent7923dbbf72da303ca1cca17efd24725668992f15 (diff)
downloadlua-842a83f09caa2ebd4bc03e0076420148ac07c808.tar.gz
lua-842a83f09caa2ebd4bc03e0076420148ac07c808.tar.bz2
lua-842a83f09caa2ebd4bc03e0076420148ac07c808.zip
Panic functions should not raise errors
The standard panic function was using 'lua_tostring', which may raise a memory-allocation error if error value is a number.
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/lauxlib.c b/lauxlib.c
index 4ca6c654..1c9082e6 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1025,9 +1025,14 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
1025} 1025}
1026 1026
1027 1027
1028/*
1029** Standard panic funcion just prints an error message. The test
1030** with 'lua_type' avoids possible memory errors in 'lua_tostring'.
1031*/
1028static int panic (lua_State *L) { 1032static int panic (lua_State *L) {
1029 const char *msg = lua_tostring(L, -1); 1033 const char *msg = (lua_type(L, -1) == LUA_TSTRING)
1030 if (msg == NULL) msg = "error object is not a string"; 1034 ? lua_tostring(L, -1)
1035 : "error object is not a string";
1031 lua_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n", 1036 lua_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
1032 msg); 1037 msg);
1033 return 0; /* return to Lua to abort */ 1038 return 0; /* return to Lua to abort */