1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-15 09:25:37 +02:00

Increase safety checks around ObjectRefs

This commit is contained in:
sfan5
2024-10-07 21:02:32 +02:00
parent 41091a147c
commit c8dc9c2b8d
6 changed files with 27 additions and 12 deletions

View File

@@ -2776,9 +2776,11 @@ void ObjectRef::create(lua_State *L, ServerActiveObject *object)
lua_setmetatable(L, -2);
}
void ObjectRef::set_null(lua_State *L)
void ObjectRef::set_null(lua_State *L, void *expect)
{
ObjectRef *obj = checkObject<ObjectRef>(L, -1);
assert(obj);
FATAL_ERROR_IF(obj->m_object != expect, "ObjectRef table was messed with");
obj->m_object = nullptr;
}

View File

@@ -38,10 +38,12 @@ public:
~ObjectRef() = default;
// Creates an ObjectRef and leaves it on top of stack
// Not callable from Lua; all references are created on the C side.
// NOTE: do not call this, use `ScriptApiBase::objectrefGetOrCreate()`!
static void create(lua_State *L, ServerActiveObject *object);
static void set_null(lua_State *L);
// Clear the pointer in the ObjectRef (at -1).
// Throws an fatal error if the object pointer wasn't `expect`.
static void set_null(lua_State *L, void *expect);
static void Register(lua_State *L);