mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 21:33:47 -07:00
bug fix - 8efe9f23fa
This commit is contained in:
parent
d5e843c750
commit
f34c746471
1 changed files with 8 additions and 4 deletions
|
@ -4,7 +4,7 @@
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#define ltablib_c
|
#define ltablib_c
|
||||||
|
@ -134,14 +134,18 @@ static int pack(lua_State *L) {
|
||||||
|
|
||||||
|
|
||||||
static int unpack(lua_State *L) {
|
static int unpack(lua_State *L) {
|
||||||
int i, e, n;
|
int i, e;
|
||||||
|
unsigned int n;
|
||||||
luaL_checktype(L, 1, LUA_TTABLE);
|
luaL_checktype(L, 1, LUA_TTABLE);
|
||||||
i = luaL_optint(L, 2, 1);
|
i = luaL_optint(L, 2, 1);
|
||||||
e = luaL_opt(L, luaL_checkint, 3, luaL_len(L, 1));
|
e = luaL_opt(L, luaL_checkint, 3, luaL_len(L, 1));
|
||||||
if (i > e) return 0; /* empty range */
|
if (i > e) return 0; /* empty range */
|
||||||
n = e - i + 1; /* number of elements */
|
|
||||||
if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */
|
n = (unsigned int)e - (unsigned int)i; /* number of elements minus 1 */
|
||||||
|
|
||||||
|
if (n > (INT_MAX - 10) || !lua_checkstack(L, ++n))
|
||||||
return luaL_error(L, "too many results to unpack");
|
return luaL_error(L, "too many results to unpack");
|
||||||
|
|
||||||
lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */
|
lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */
|
||||||
while (i++ < e) /* push arg[i + 1...e] */
|
while (i++ < e) /* push arg[i + 1...e] */
|
||||||
lua_rawgeti(L, 1, i);
|
lua_rawgeti(L, 1, i);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue