diff options
author | Jude Melton-Houghton <jwmhjwmh@gmail.com> | 2022-09-11 13:28:37 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-11 19:28:37 +0200 |
commit | fe13f9dfd12c0a7f08355b83e34e7dec1bfdd86d (patch) | |
tree | 265ac5b7ce70fc411ce9436dfbae152b4ce5bd6b /src/script/lua_api/l_item.cpp | |
parent | 7486f184c3c800d462cf783a0f10289dcf9ebec6 (diff) | |
download | minetest-fe13f9dfd12c0a7f08355b83e34e7dec1bfdd86d.tar.xz |
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.
Diffstat (limited to 'src/script/lua_api/l_item.cpp')
-rw-r--r-- | src/script/lua_api/l_item.cpp | 13 |
1 files changed, 2 insertions, 11 deletions
diff --git a/src/script/lua_api/l_item.cpp b/src/script/lua_api/l_item.cpp index cf0fcce71..bf73e78c1 100644 --- a/src/script/lua_api/l_item.cpp +++ b/src/script/lua_api/l_item.cpp @@ -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) |