aboutsummaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-06-09 16:12:01 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-06-09 16:12:01 -0300
commit364e569945c044fd18c70ee1bc851364534aef97 (patch)
treead461207558d0452455a8180cf5d8b1e6e37d0be /lauxlib.c
parent63295f1f7fa052fabcb4d69d49203cf33a7deef0 (diff)
downloadlua-364e569945c044fd18c70ee1bc851364534aef97.tar.gz
lua-364e569945c044fd18c70ee1bc851364534aef97.tar.bz2
lua-364e569945c044fd18c70ee1bc851364534aef97.zip
Avoid calling 'fprintf' with NULL
Avoid undefined behavior in calls like «fprintf("%s", NULL)». ('lua_writestringerror' is implemented as 'fprintf', and 'lua_tostring' can return NULL if object is not a string.)
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/lauxlib.c b/lauxlib.c
index e6d74168..e3d9be37 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -995,8 +995,10 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
995 995
996 996
997static int panic (lua_State *L) { 997static int panic (lua_State *L) {
998 const char *msg = lua_tostring(L, -1);
999 if (msg == NULL) msg = "error object is not a string";
998 lua_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n", 1000 lua_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
999 lua_tostring(L, -1)); 1001 msg);
1000 return 0; /* return to Lua to abort */ 1002 return 0; /* return to Lua to abort */
1001} 1003}
1002 1004