aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_item.h
diff options
context:
space:
mode:
authorJude Melton-Houghton <jwmhjwmh@gmail.com>2022-09-11 13:28:37 -0400
committersfan5 <sfan5@live.de>2022-09-14 13:48:06 +0200
commitf8bb0cd3d1da9d2d9d8dffe78cd0fb651e16a8af (patch)
treee301b693df3b4b79302bbca1221887046da84d28 /src/script/lua_api/l_item.h
parent129aef758ece753e684aa494e5471045a996ac8f (diff)
downloadminetest-f8bb0cd3d1da9d2d9d8dffe78cd0fb651e16a8af.tar.gz
minetest-f8bb0cd3d1da9d2d9d8dffe78cd0fb651e16a8af.tar.bz2
minetest-f8bb0cd3d1da9d2d9d8dffe78cd0fb651e16a8af.zip
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.h')
-rw-r--r--src/script/lua_api/l_item.h13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/script/lua_api/l_item.h b/src/script/lua_api/l_item.h
index a392555d2..72b1922dd 100644
--- a/src/script/lua_api/l_item.h
+++ b/src/script/lua_api/l_item.h
@@ -21,11 +21,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "lua_api/l_base.h"
#include "inventory.h" // ItemStack
+#include "util/pointer.h"
-class LuaItemStack : public ModApiBase {
+class LuaItemStack : public ModApiBase, public IntrusiveReferenceCounted {
private:
ItemStack m_stack;
+ LuaItemStack(const ItemStack &item);
+ ~LuaItemStack() = default;
+
static const char className[];
static const luaL_Reg methods[];
@@ -138,11 +142,10 @@ private:
static int l_peek_item(lua_State *L);
public:
- LuaItemStack(const ItemStack &item);
- ~LuaItemStack() = default;
+ DISABLE_CLASS_COPY(LuaItemStack)
- const ItemStack& getItem() const;
- ItemStack& getItem();
+ inline const ItemStack& getItem() const { return m_stack; }
+ inline ItemStack& getItem() { return m_stack; }
// LuaItemStack(itemstack or itemstring or table or nil)
// Creates an LuaItemStack and leaves it on top of stack