From a76c8729535c3c06b62c94b86e3dfb3e0c1179c9 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Tue, 27 Aug 2024 22:10:00 +0700 Subject: [PATCH] set_member: more details for entity checking fix validating for AMX_NULLENT index --- reapi/src/natives/natives_helper.h | 2 +- reapi/src/natives/natives_members.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/reapi/src/natives/natives_helper.h b/reapi/src/natives/natives_helper.h index efc5ac02..658b301e 100644 --- a/reapi/src/natives/natives_helper.h +++ b/reapi/src/natives/natives_helper.h @@ -11,7 +11,7 @@ #define CHECK_INSTANCE_OF(x, y) if (unlikely(dynamic_cast((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; } class CAmxArg { diff --git a/reapi/src/natives/natives_members.cpp b/reapi/src/natives/natives_members.cpp index 2ebf9399..368570e2 100644 --- a/reapi/src/natives/natives_members.cpp +++ b/reapi/src/natives/natives_members.cpp @@ -939,7 +939,7 @@ 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(*value); set_member(pdata, member->offset, pEntity, element); @@ -947,7 +947,7 @@ cell set_member(AMX *amx, void* pdata, const member_t *member, cell* value, size } case MEMBER_EHANDLE: { - ENTITY_VALIDATE(*value); + AMX_ENTITY_VALIDATE(*value, member->name); // native set_member(_index, any:_member, _value, _elem); EHANDLE& ehandle = get_member(pdata, member->offset, element); edict_t *pEdictValue = edictByIndexAmx(*value); @@ -956,7 +956,7 @@ 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(pdata, member->offset, pEdictValue, element); @@ -964,7 +964,7 @@ cell set_member(AMX *amx, void* pdata, const member_t *member, cell* value, size } 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(pdata, member->offset, pev, element);