Check type of Squirrel constructor_stub() instance

This prevents manual invocations of the native class constructor with an
invalid value.
This commit is contained in:
Alexander 'z33ky' Hirsch 2025-06-23 20:55:13 +02:00
parent 9c494b6eeb
commit 9c740a891e

View File

@ -1562,15 +1562,23 @@ SQInteger constructor_stub(HSQUIRRELVM vm)
Assert(pSquirrelVM); Assert(pSquirrelVM);
sq_resetobject(&pSquirrelVM->lastError_); sq_resetobject(&pSquirrelVM->lastError_);
void* instance = pClassDesc->m_pfnConstruct();
// expect construction to always succeed
Assert(sq_isnull(pSquirrelVM->lastError_));
{ {
SQUserPointer p; SQUserPointer p;
sq_getinstanceup(vm, 1, &p, 0); if (SQ_FAILED(sq_getinstanceup(vm, 1, &p, 0)))
{
return SQ_ERROR;
}
if (!p)
{
return sq_throwerror(vm, "Accessed null instance");
}
void* instance = pClassDesc->m_pfnConstruct();
// expect construction to always succeed
Assert(sq_isnull(pSquirrelVM->lastError_));
new(p) ClassInstanceData(instance, pClassDesc, nullptr, true); new(p) ClassInstanceData(instance, pClassDesc, nullptr, true);
} }