diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-11-24 16:08:55 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-11-24 16:08:55 -0300 |
commit | 842a83f09caa2ebd4bc03e0076420148ac07c808 (patch) | |
tree | 92eca69ee75b32156b14c1a9d0b5a31f16ef9118 /lauxlib.c | |
parent | 7923dbbf72da303ca1cca17efd24725668992f15 (diff) | |
download | lua-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.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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 | */ | ||
1028 | static int panic (lua_State *L) { | 1032 | static 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 */ |