Skip to content

Commit dc0cfaa

Browse files
committed
Guard Squirrel constructor_stub() invocations from invalid class parameters
This prevents manual invocations of the native class constructor for non-class values or non-native classes.
1 parent 449859f commit dc0cfaa

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

sp/src/vscript/vscript_squirrel.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,13 @@ SQInteger destructor_stub_instance(SQUserPointer p, SQInteger size)
15421542
SQInteger constructor_stub(HSQUIRRELVM vm)
15431543
{
15441544
ScriptClassDesc_t* pClassDesc = nullptr;
1545-
sq_gettypetag(vm, 1, (SQUserPointer*)&pClassDesc);
1545+
if (SQ_FAILED(sq_gettypetag(vm, 1, (SQUserPointer*)&pClassDesc))) {
1546+
return sq_throwerror(vm, "Expected native class");
1547+
}
1548+
1549+
if (!pClassDesc || (void*)pClassDesc == TYPETAG_VECTOR) {
1550+
return sq_throwerror(vm, "Unable to obtain native class description");
1551+
}
15461552

15471553
if (!pClassDesc->m_pfnConstruct)
15481554
{

0 commit comments

Comments
 (0)