Skip to content

Commit f6b27ab

Browse files
committed
Check type of Squirrel constructor_stub() instance
This prevents manual invocations of the native class constructor with an invalid value.
1 parent 55ed1b7 commit f6b27ab

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

sp/src/vscript/vscript_squirrel.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,15 +1569,23 @@ SQInteger constructor_stub(HSQUIRRELVM vm)
15691569
Assert(pSquirrelVM);
15701570

15711571
sq_resetobject(&pSquirrelVM->lastError_);
1572+
{
1573+
SQUserPointer p;
1574+
if (SQ_FAILED(sq_getinstanceup(vm, 1, &p, 0)))
1575+
{
1576+
return sq_throwerror(vm, "Expected class userpointer");
1577+
}
15721578

1573-
void* instance = pClassDesc->m_pfnConstruct();
1579+
if (!p)
1580+
{
1581+
return sq_throwerror(vm, "Accessed null instance");
1582+
}
15741583

1575-
// expect construction to always succeed
1576-
Assert(sq_isnull(pSquirrelVM->lastError_));
1584+
void* instance = pClassDesc->m_pfnConstruct();
1585+
1586+
// expect construction to always succeed
1587+
Assert(sq_isnull(pSquirrelVM->lastError_));
15771588

1578-
{
1579-
SQUserPointer p;
1580-
sq_getinstanceup(vm, 1, &p, 0);
15811589
new(p) ClassInstanceData(instance, pClassDesc, nullptr, true);
15821590
}
15831591

0 commit comments

Comments
 (0)