1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Fix potential use-after-free with item metadata (#12729)

This fixes a use-after-free bug in the case where itemstack metadata is accessed after the itemstack has been garbage-collected.
This commit is contained in:
Jude Melton-Houghton 2022-09-11 13:28:37 -04:00 committed by GitHub
parent 7486f184c3
commit fe13f9dfd1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 26 deletions

View file

@ -34,7 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
int LuaItemStack::gc_object(lua_State *L)
{
LuaItemStack *o = *(LuaItemStack **)(lua_touserdata(L, 1));
delete o;
o->drop();
return 0;
}
@ -152,7 +152,7 @@ int LuaItemStack::l_get_meta(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
LuaItemStack *o = checkobject(L, 1);
ItemStackMetaRef::create(L, &o->m_stack);
ItemStackMetaRef::create(L, o);
return 1;
}
@ -438,15 +438,6 @@ LuaItemStack::LuaItemStack(const ItemStack &item):
{
}
const ItemStack& LuaItemStack::getItem() const
{
return m_stack;
}
ItemStack& LuaItemStack::getItem()
{
return m_stack;
}
// LuaItemStack(itemstack or itemstring or table or nil)
// Creates an LuaItemStack and leaves it on top of stack
int LuaItemStack::create_object(lua_State *L)