aboutsummaryrefslogtreecommitdiff
path: root/lbaselib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-09-22 13:10:39 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-09-22 13:10:39 -0300
commitdeac067ed39a44c001599c0d15de09872496b2aa (patch)
treed7373651e7d54a8ca5ffa4841379a4d9149164aa /lbaselib.c
parent2ff34717227b8046b0fdcb96206f11f5e888664e (diff)
downloadlua-deac067ed39a44c001599c0d15de09872496b2aa.tar.gz
lua-deac067ed39a44c001599c0d15de09872496b2aa.tar.bz2
lua-deac067ed39a44c001599c0d15de09872496b2aa.zip
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).
Diffstat (limited to 'lbaselib.c')
-rw-r--r--lbaselib.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/lbaselib.c b/lbaselib.c
index fd6687e6..912c4cc6 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -285,7 +285,8 @@ static int luaB_pairs (lua_State *L) {
285** Traversal function for 'ipairs' 285** Traversal function for 'ipairs'
286*/ 286*/
287static int ipairsaux (lua_State *L) { 287static int ipairsaux (lua_State *L) {
288 lua_Integer i = luaL_checkinteger(L, 2) + 1; 288 lua_Integer i = luaL_checkinteger(L, 2);
289 i = luaL_intop(+, i, 1);
289 lua_pushinteger(L, i); 290 lua_pushinteger(L, i);
290 return (lua_geti(L, 1, i) == LUA_TNIL) ? 1 : 2; 291 return (lua_geti(L, 1, i) == LUA_TNIL) ? 1 : 2;
291} 292}