diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2008-02-14 14:03:09 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2008-02-14 14:03:09 -0200 |
commit | 5ac3386888347cb4d9b3ffc6d5abd1a4cfc8d1c9 (patch) | |
tree | a17703a2911e4bfdd41ed4574a4735dbdaf757c9 /lbaselib.c | |
parent | 6d182faab65f7634802904c489de6dabcb56830a (diff) | |
download | lua-5ac3386888347cb4d9b3ffc6d5abd1a4cfc8d1c9.tar.gz lua-5ac3386888347cb4d9b3ffc6d5abd1a4cfc8d1c9.tar.bz2 lua-5ac3386888347cb4d9b3ffc6d5abd1a4cfc8d1c9.zip |
bug: unpack with maximum indices may crash due to arithmetic overflow
Diffstat (limited to 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.202 2008/01/03 17:07:59 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.203 2008/02/11 19:14:52 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -353,10 +353,12 @@ static int luaB_unpack (lua_State *L) { | |||
353 | luaL_checktype(L, 1, LUA_TTABLE); | 353 | luaL_checktype(L, 1, LUA_TTABLE); |
354 | i = luaL_optint(L, 2, 1); | 354 | i = luaL_optint(L, 2, 1); |
355 | e = luaL_opt(L, luaL_checkint, 3, (int)lua_objlen(L, 1)); | 355 | e = luaL_opt(L, luaL_checkint, 3, (int)lua_objlen(L, 1)); |
356 | if (i > e) return 0; /* empty range */ | ||
356 | n = e - i + 1; /* number of elements */ | 357 | n = e - i + 1; /* number of elements */ |
357 | if (n <= 0) return 0; /* empty range */ | 358 | if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */ |
358 | luaL_checkstack(L, n, "table too big to unpack"); | 359 | return luaL_error(L, "too many results to unpack"); |
359 | for (; i<=e; i++) /* push arg[i...e] */ | 360 | lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */ |
361 | while (i++ < e) /* push arg[i + 1...e] */ | ||
360 | lua_rawgeti(L, 1, i); | 362 | lua_rawgeti(L, 1, i); |
361 | return n; | 363 | return n; |
362 | } | 364 | } |