avoid limits in filename size

This commit is contained in:
Roberto Ierusalimschy 2002-05-02 13:55:55 -03:00
parent 9a0f0dcc77
commit 3c6a383d62
1 changed files with 15 additions and 7 deletions

22
lapi.c
View File

@ -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 ** Lua API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
#include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -31,6 +30,11 @@ const char lua_ident[] =
"$URL: www.lua.org $\n"; "$URL: www.lua.org $\n";
#ifndef lua_filerror
#include <errno.h>
#define lua_fileerror (strerror(errno))
#endif
#ifndef api_check #ifndef api_check
#define api_check(L, o) ((void)1) #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) { static int errfile (lua_State *L, const char *filename) {
char buff[150]; if (filename == NULL) filename = "stdin";
sprintf(buff, "cannot read file `%.80s' (%.40s)", filename, strerror(errno)); lua_pushliteral(L, "cannot read ");
lua_pushstring(L, buff); lua_pushstring(L, filename);
lua_pushliteral(L, ": ");
lua_pushstring(L, lua_fileerror);
lua_concat(L, 4);
return LUA_ERRFILE; return LUA_ERRFILE;
} }
LUA_API int lua_loadfile (lua_State *L, const char *filename) { LUA_API int lua_loadfile (lua_State *L, const char *filename) {
ZIO z; ZIO z;
const char *luafname; /* name used by lua */
int status; int status;
int bin; /* flag for file mode */ int bin; /* flag for file mode */
int nlevel; /* level on the stack of filename */ 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); lua_concat(L, 2);
} }
nlevel = lua_gettop(L); nlevel = lua_gettop(L);
filename = lua_tostring(L, -1); /* filename = `@'..filename */ luafname = lua_tostring(L, -1); /* luafname = `@'..filename */
luaZ_Fopen(&z, f, filename); luaZ_Fopen(&z, f, luafname);
status = luaD_protectedparser(L, &z, bin); status = luaD_protectedparser(L, &z, bin);
if (ferror(f)) if (ferror(f))
return errfile(L, filename); return errfile(L, filename);