diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-04-11 15:01:35 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-04-11 15:01:35 -0300 |
| commit | 2873d4efff18e972a94a6d20c231b0ac062bc4ca (patch) | |
| tree | 53f0f1a1bc60b521fa5ff50aaf6c2813275c7c08 | |
| parent | a7ea0c71e80fa9f5f433b5495108164e6131404e (diff) | |
| download | lua-2873d4efff18e972a94a6d20c231b0ac062bc4ca.tar.gz lua-2873d4efff18e972a94a6d20c231b0ac062bc4ca.tar.bz2 lua-2873d4efff18e972a94a6d20c231b0ac062bc4ca.zip | |
stack could overflow with too many command-line arguments
| -rw-r--r-- | lua.c | 25 |
1 files changed, 12 insertions, 13 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.c,v 1.139 2005/03/29 16:47:48 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.140 2005/03/30 19:50:29 roberto Exp roberto $ |
| 3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -102,15 +102,14 @@ static void print_version (void) { | |||
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | 104 | ||
| 105 | static int getargs (lua_State *L, char *argv[], int n) { | 105 | static int getargs (lua_State *L, int argc, char **argv, int n) { |
| 106 | int i, narg; | 106 | int narg = argc - (n + 1); /* number of arguments to the script */ |
| 107 | for (i=n+1; argv[i]; i++) { | 107 | int i; |
| 108 | luaL_checkstack(L, 1, "too many arguments to script"); | 108 | luaL_checkstack(L, narg + 3, "too many arguments to script"); |
| 109 | for (i=n+1; i < argc; i++) | ||
| 109 | lua_pushstring(L, argv[i]); | 110 | lua_pushstring(L, argv[i]); |
| 110 | } | ||
| 111 | narg = i-(n+1); /* number of arguments to the script (not to `lua.c') */ | ||
| 112 | lua_newtable(L); | 111 | lua_newtable(L); |
| 113 | for (i=0; argv[i]; i++) { | 112 | for (i=0; i < argc; i++) { |
| 114 | lua_pushstring(L, argv[i]); | 113 | lua_pushstring(L, argv[i]); |
| 115 | lua_rawseti(L, -2, i - n); | 114 | lua_rawseti(L, -2, i - n); |
| 116 | } | 115 | } |
| @@ -230,7 +229,7 @@ static int checkvar (lua_State *L) { | |||
| 230 | 229 | ||
| 231 | #define clearinteractive(i) (*i &= 2) | 230 | #define clearinteractive(i) (*i &= 2) |
| 232 | 231 | ||
| 233 | static int handle_argv (lua_State *L, char *argv[], int *interactive) { | 232 | static int handle_argv (lua_State *L, int argc, char **argv, int *interactive) { |
| 234 | if (argv[1] == NULL) { /* no arguments? */ | 233 | if (argv[1] == NULL) { /* no arguments? */ |
| 235 | *interactive = 0; | 234 | *interactive = 0; |
| 236 | if (lua_stdin_is_tty()) | 235 | if (lua_stdin_is_tty()) |
| @@ -303,9 +302,9 @@ static int handle_argv (lua_State *L, char *argv[], int *interactive) { | |||
| 303 | } | 302 | } |
| 304 | } endloop: | 303 | } endloop: |
| 305 | if (argv[i] != NULL) { | 304 | if (argv[i] != NULL) { |
| 306 | const char *filename = argv[i]; | ||
| 307 | int narg = getargs(L, argv, i); /* collect arguments */ | ||
| 308 | int status; | 305 | int status; |
| 306 | const char *filename = argv[i]; | ||
| 307 | int narg = getargs(L, argc, argv, i); /* collect arguments */ | ||
| 309 | lua_setglobal(L, "arg"); | 308 | lua_setglobal(L, "arg"); |
| 310 | clearinteractive(interactive); | 309 | clearinteractive(interactive); |
| 311 | status = luaL_loadfile(L, filename); | 310 | status = luaL_loadfile(L, filename); |
| @@ -347,7 +346,7 @@ static int pmain (lua_State *L) { | |||
| 347 | luaopen_stdlibs(L); /* open libraries */ | 346 | luaopen_stdlibs(L); /* open libraries */ |
| 348 | status = handle_luainit(L); | 347 | status = handle_luainit(L); |
| 349 | if (status == 0) { | 348 | if (status == 0) { |
| 350 | status = handle_argv(L, s->argv, &interactive); | 349 | status = handle_argv(L, s->argc, s->argv, &interactive); |
| 351 | if (status == 0 && interactive) dotty(L); | 350 | if (status == 0 && interactive) dotty(L); |
| 352 | } | 351 | } |
| 353 | s->status = status; | 352 | s->status = status; |
| @@ -355,7 +354,7 @@ static int pmain (lua_State *L) { | |||
| 355 | } | 354 | } |
| 356 | 355 | ||
| 357 | 356 | ||
| 358 | int main (int argc, char *argv[]) { | 357 | int main (int argc, char **argv) { |
| 359 | int status; | 358 | int status; |
| 360 | struct Smain s; | 359 | struct Smain s; |
| 361 | lua_State *L = lua_open(); /* create state */ | 360 | lua_State *L = lua_open(); /* create state */ |
