From deac067ed39a44c001599c0d15de09872496b2aa Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 22 Sep 2021 13:10:39 -0300 Subject: Avoid overflows when incrementing parameters in C Any C function can receive maxinteger as an integer argument, and therefore cannot increment it without some care (e.g., doing unsigned arithmetic as the core does). --- ltablib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ltablib.c') diff --git a/ltablib.c b/ltablib.c index dbfe2509..868d78fd 100644 --- a/ltablib.c +++ b/ltablib.c @@ -59,8 +59,9 @@ static void checktab (lua_State *L, int arg, int what) { static int tinsert (lua_State *L) { - lua_Integer e = aux_getn(L, 1, TAB_RW) + 1; /* first empty element */ lua_Integer pos; /* where to insert new element */ + lua_Integer e = aux_getn(L, 1, TAB_RW); + e = luaL_intop(+, e, 1); /* first empty element */ switch (lua_gettop(L)) { case 2: { /* called with only 2 arguments */ pos = e; /* insert new element at the end */ -- cgit v1.2.3-55-g6feb