From 364e569945c044fd18c70ee1bc851364534aef97 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 9 Jun 2020 16:12:01 -0300 Subject: Avoid calling 'fprintf' with NULL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.) --- ldblib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ldblib.c') diff --git a/ldblib.c b/ldblib.c index 745cfd27..59eb8f0e 100644 --- a/ldblib.c +++ b/ldblib.c @@ -417,7 +417,7 @@ static int db_debug (lua_State *L) { return 0; if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || lua_pcall(L, 0, 0, 0)) - lua_writestringerror("%s\n", lua_tostring(L, -1)); + lua_writestringerror("%s\n", luaL_tolstring(L, -1, NULL)); lua_settop(L, 0); /* remove eventual returns */ } } -- cgit v1.2.3-55-g6feb