Skip to content

Commit f27dc2f

Browse files
sdktools: Throw error when invalid address passed to SDKCall (#1265)
1 parent 1282f13 commit f27dc2f

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

extensions/sdktools/vcaller.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ enum SDKPassMethod
4545
SDKPass_ByRef, /**< Pass an object by reference */
4646
};
4747

48+
//memory addresses below 0x10000 are automatically considered invalid for dereferencing
49+
#define VALID_MINIMUM_MEMORY_ADDRESS 0x10000
50+
4851
int s_vtbl_index = -1;
4952
void *s_call_addr = NULL;
5053
ValveCallType s_vcalltype = ValveCall_Static;
@@ -365,6 +368,17 @@ static cell_t SDKCall(IPluginContext *pContext, const cell_t *params)
365368
pContext->LocalToPhysAddr(params[startparam], &cell);
366369
void *thisptr = reinterpret_cast<void*>(*cell);
367370

371+
if (thisptr == nullptr)
372+
{
373+
vc->stk_put(ptr);
374+
return pContext->ThrowNativeError("ThisPtr address cannot be null");
375+
}
376+
else if (reinterpret_cast<uintptr_t>(thisptr) < VALID_MINIMUM_MEMORY_ADDRESS)
377+
{
378+
vc->stk_put(ptr);
379+
return pContext->ThrowNativeError("Invalid ThisPtr address 0x%x is pointing to reserved memory.", thisptr);
380+
}
381+
368382
*(void **)ptr = thisptr;
369383
startparam++;
370384
}

0 commit comments

Comments
 (0)