Ensure the squirrel instance for native member function call actually has userpointer type

This prevents memory errors when incorrectly invoking native member
functions from Squirrel.
This commit is contained in:
Alexander 'z33ky' Hirsch 2025-06-11 02:11:09 +02:00
parent cdafc1278e
commit c851fc9bfb

View File

@ -1324,7 +1324,10 @@ SQInteger function_stub(HSQUIRRELVM vm)
SQInteger top = sq_gettop(vm); SQInteger top = sq_gettop(vm);
SQUserPointer userptr = nullptr; SQUserPointer userptr = nullptr;
sq_getuserpointer(vm, top, &userptr); if (SQ_FAILED(sq_getuserpointer(vm, top, &userptr)))
{
return sq_throwerror(vm, "Expected userpointer");
}
Assert(userptr); Assert(userptr);
@ -1425,7 +1428,10 @@ SQInteger function_stub(HSQUIRRELVM vm)
if (pFunc->m_flags & SF_MEMBER_FUNC) if (pFunc->m_flags & SF_MEMBER_FUNC)
{ {
SQUserPointer self; SQUserPointer self;
sq_getinstanceup(vm, 1, &self, nullptr); if (SQ_FAILED(sq_getinstanceup(vm, 1, &self, 0)))
{
return sq_throwerror(vm, "Expected class userpointer");
}
if (!self) if (!self)
{ {