From 36d7747f18aeb02c317e6ab4dd5542071ad41842 Mon Sep 17 00:00:00 2001 From: Juan Carrano Date: Mon, 7 May 2018 13:59:06 +0200 Subject: [PATCH 4/7] Remove os.tmpname. It is a potential source of bugs, causes compiler warnings when building without POSIX, behaves differently under POSIX, and cannot be fixed. Also, it used a stack variable whose size could be really big under certain C standard libraries. Any program using os.tmpname is should be fixed. --- loslib.c | 51 --------------------------------------------------- 1 file changed, 51 deletions(-) diff --git a/loslib.c b/loslib.c index dd2bb378..69a5f531 100644 --- a/loslib.c +++ b/loslib.c @@ -99,45 +99,6 @@ static time_t l_checktime (lua_State *L, int arg) { /* }================================================================== */ -/* -** {================================================================== -** Configuration for 'tmpnam': -** By default, Lua uses tmpnam except when POSIX is available, where -** it uses mkstemp. -** =================================================================== -*/ -#if !defined(lua_tmpnam) /* { */ - -#if defined(LUA_USE_POSIX) /* { */ - -#include - -#define LUA_TMPNAMBUFSIZE 32 - -#if !defined(LUA_TMPNAMTEMPLATE) -#define LUA_TMPNAMTEMPLATE "/tmp/lua_XXXXXX" -#endif - -#define lua_tmpnam(b,e) { \ - strcpy(b, LUA_TMPNAMTEMPLATE); \ - e = mkstemp(b); \ - if (e != -1) close(e); \ - e = (e == -1); } - -#else /* }{ */ - -/* ISO C definitions */ -#define LUA_TMPNAMBUFSIZE L_tmpnam -#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); } - -#endif /* } */ - -#endif /* } */ -/* }================================================================== */ - - - - static int os_execute (lua_State *L) { const char *cmd = luaL_optstring(L, 1, NULL); int stat = system(cmd); @@ -163,17 +124,6 @@ static int os_rename (lua_State *L) { } -static int os_tmpname (lua_State *L) { - char buff[LUA_TMPNAMBUFSIZE]; - int err; - lua_tmpnam(buff, err); - if (err) - return luaL_error(L, "unable to generate a unique filename"); - lua_pushstring(L, buff); - return 1; -} - - static int os_getenv (lua_State *L) { lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ return 1; @@ -392,7 +342,6 @@ static const luaL_Reg syslib[] = { {"rename", os_rename}, {"setlocale", os_setlocale}, {"time", os_time}, - {"tmpname", os_tmpname}, {NULL, NULL} }; -- 2.25.1