From d472978d007af1930fadf3fb9fe455554cbee29c Mon Sep 17 00:00:00 2001 From: Michael Werle Date: Sun, 3 Nov 2024 12:32:49 +0900 Subject: [PATCH] Fix Lua stack size mismatch in l_space_spawn_cargo_near Also add additional validation to LuaObjectBase::PushRegisterd() and LuaObjectBase::Allocate(). --- src/lua/LuaObject.cpp | 8 +++++++- src/lua/LuaSpace.cpp | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lua/LuaObject.cpp b/src/lua/LuaObject.cpp index 5e6519a793..0a247451d8 100644 --- a/src/lua/LuaObject.cpp +++ b/src/lua/LuaObject.cpp @@ -450,6 +450,7 @@ bool LuaObjectBase::PushRegistered(LuaWrappable *o) if (!o) { lua_pushnil(l); + LUA_DEBUG_END(l, 1); return true; } @@ -877,5 +878,10 @@ bool LuaObjectBase::DeserializeFromJson(lua_State *l, const Json &obj) void *LuaObjectBase::Allocate(size_t n) { lua_State *l = Lua::manager->GetLuaState(); - return lua_newuserdata(l, n); + LUA_DEBUG_START(l); + + void *userdata = lua_newuserdata(l, n); + + LUA_DEBUG_END(l, 1); + return userdata; } diff --git a/src/lua/LuaSpace.cpp b/src/lua/LuaSpace.cpp index 5fa179f4d6..37392bf418 100644 --- a/src/lua/LuaSpace.cpp +++ b/src/lua/LuaSpace.cpp @@ -828,6 +828,8 @@ static int l_space_spawn_cargo_near(lua_State *l) } else { c_body = new CargoBody(model, LuaRef(l, 1)); } + lua_pop(l, 1); // pop model_name + Body *nearbody = LuaObject::CheckFromLua(2); float min_dist = luaL_checknumber(l, 3); float max_dist = luaL_checknumber(l, 4);