From 3c6a383d6239629fd8858e0d59bcdab25138bcc1 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 2 May 2002 13:55:55 -0300 Subject: [PATCH] avoid limits in filename size --- lapi.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lapi.c b/lapi.c index 42ed4a82..1bc5f340 100644 --- a/lapi.c +++ b/lapi.c @@ -1,11 +1,10 @@ /* -** $Id: lapi.c,v 1.185 2002/04/22 14:40:50 roberto Exp roberto $ +** $Id: lapi.c,v 1.186 2002/05/01 20:48:12 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ -#include #include #include @@ -31,6 +30,11 @@ const char lua_ident[] = "$URL: www.lua.org $\n"; +#ifndef lua_filerror +#include +#define lua_fileerror (strerror(errno)) +#endif + #ifndef api_check #define api_check(L, o) ((void)1) @@ -543,15 +547,19 @@ LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errf) { static int errfile (lua_State *L, const char *filename) { - char buff[150]; - sprintf(buff, "cannot read file `%.80s' (%.40s)", filename, strerror(errno)); - lua_pushstring(L, buff); + if (filename == NULL) filename = "stdin"; + lua_pushliteral(L, "cannot read "); + lua_pushstring(L, filename); + lua_pushliteral(L, ": "); + lua_pushstring(L, lua_fileerror); + lua_concat(L, 4); return LUA_ERRFILE; } LUA_API int lua_loadfile (lua_State *L, const char *filename) { ZIO z; + const char *luafname; /* name used by lua */ int status; int bin; /* flag for file mode */ int nlevel; /* level on the stack of filename */ @@ -571,8 +579,8 @@ LUA_API int lua_loadfile (lua_State *L, const char *filename) { lua_concat(L, 2); } nlevel = lua_gettop(L); - filename = lua_tostring(L, -1); /* filename = `@'..filename */ - luaZ_Fopen(&z, f, filename); + luafname = lua_tostring(L, -1); /* luafname = `@'..filename */ + luaZ_Fopen(&z, f, luafname); status = luaD_protectedparser(L, &z, bin); if (ferror(f)) return errfile(L, filename);