Skip to content

Commit

Permalink
Fix Lua stack size mismatch in l_space_spawn_cargo_near
Browse files Browse the repository at this point in the history
Also add additional validation to LuaObjectBase::PushRegisterd() and
LuaObjectBase::Allocate().
  • Loading branch information
mwerle committed Nov 3, 2024
1 parent 355781d commit d472978
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lua/LuaObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ bool LuaObjectBase::PushRegistered(LuaWrappable *o)

if (!o) {
lua_pushnil(l);
LUA_DEBUG_END(l, 1);
return true;
}

Expand Down Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions src/lua/LuaSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Body>::CheckFromLua(2);
float min_dist = luaL_checknumber(l, 3);
float max_dist = luaL_checknumber(l, 4);
Expand Down

0 comments on commit d472978

Please sign in to comment.