Skip to content

Commit

Permalink
set_member: more details for entity checking
Browse files Browse the repository at this point in the history
fix validating for AMX_NULLENT index
  • Loading branch information
s1lentq committed Aug 27, 2024
1 parent 22761b7 commit a76c872
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion reapi/src/natives/natives_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define CHECK_INSTANCE_OF(x, y) if (unlikely(dynamic_cast<x *>((x::BaseClass *)y) == nullptr)) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid entity %d ('%s'), is not an instance of the base class '%s'", __FUNCTION__, indexOfEdict(y->pev), STRING(y->pev->classname), #x); return FALSE; }
#define CHECK_REQUIREMENTS(x) if (unlikely(!api_cfg.has##x())) { AMXX_LogError(amx, AMX_ERR_NATIVE, "Native '%s' is not available, %s required.", __FUNCTION__, #x); return FALSE; } if (!g_RehldsMessageManager) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: %s message manager not initialized.", __FUNCTION__, #x); return FALSE; }

#define ENTITY_VALIDATE(x) if (unlikely(x < 0 || x > gpGlobals->maxEntities)) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid entity index %i", __FUNCTION__, x); return FALSE; }
#define AMX_ENTITY_VALIDATE(x, y) if (unlikely(x < AMX_NULLENT || x > gpGlobals->maxEntities)) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: \"%s\" invalid entity index %i", __FUNCTION__, y, x); return FALSE; }

This comment has been minimized.

Copy link
@StevenKal

StevenKal Aug 28, 2024

x <= AMX_NULLENT!

This comment has been minimized.

Copy link
@s1lentq

s1lentq Aug 28, 2024

Author Collaborator

amxx -1 acceptable to set null pointer


class CAmxArg
{
Expand Down
8 changes: 4 additions & 4 deletions reapi/src/natives/natives_members.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,15 +939,15 @@ cell set_member(AMX *amx, void* pdata, const member_t *member, cell* value, size
switch (member->type) {
case MEMBER_CLASSPTR:
{
ENTITY_VALIDATE(*value);
AMX_ENTITY_VALIDATE(*value, member->name);
// native set_member(_index, any:_member, _value, _elem);
CBaseEntity *pEntity = getPrivate<CBaseEntity>(*value);
set_member<CBaseEntity *>(pdata, member->offset, pEntity, element);
return TRUE;
}
case MEMBER_EHANDLE:
{
ENTITY_VALIDATE(*value);
AMX_ENTITY_VALIDATE(*value, member->name);
// native set_member(_index, any:_member, _value, _elem);
EHANDLE& ehandle = get_member<EHANDLE>(pdata, member->offset, element);
edict_t *pEdictValue = edictByIndexAmx(*value);
Expand All @@ -956,15 +956,15 @@ cell set_member(AMX *amx, void* pdata, const member_t *member, cell* value, size
}
case MEMBER_EDICT:
{
ENTITY_VALIDATE(*value);
AMX_ENTITY_VALIDATE(*value, member->name);
// native set_member(_index, any:_member, _value, _elem);
edict_t *pEdictValue = edictByIndexAmx(*value);
set_member<edict_t *>(pdata, member->offset, pEdictValue, element);
return TRUE;
}
case MEMBER_EVARS:
{
ENTITY_VALIDATE(*value);
AMX_ENTITY_VALIDATE(*value, member->name);
// native set_member(_index, any:_member, _value, _elem);
entvars_t *pev = PEV(*value);
set_member<entvars_t *>(pdata, member->offset, pev, element);
Expand Down

0 comments on commit a76c872

Please sign in to comment.