From e236ad83483ec28eaff084393d88108fae92d9c3 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sun, 11 Aug 2024 20:21:12 +0200 Subject: [PATCH] Lua API: fix OOB array access in find_nodes_near (#14948) --- src/script/lua_api/l_env.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 2b3d15bea..f5ed2804c 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -970,8 +970,8 @@ int ModApiEnvBase::findNodesInArea(lua_State *L, const NodeDefManager *ndef, }); // last filter table is at top of stack - u32 i = filter.size() - 1; - do { + u32 i = filter.size(); + while (i --> 0) { if (idx[i] == 0) { // No such node found -> drop the empty table lua_pop(L, 1); @@ -979,7 +979,7 @@ int ModApiEnvBase::findNodesInArea(lua_State *L, const NodeDefManager *ndef, // This node was found -> put table into the return table lua_setfield(L, base, ndef->get(filter[i]).name.c_str()); } - } while (i-- != 0); + } assert(lua_gettop(L) == base); return 1;