From 77aa0f4f8e4d5fafd50af44b3c5febbecd6fea12 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 4 Oct 2004 20:32:26 +0000 Subject: [PATCH] Fixed bad error checking routine --- dlls/csx/source/rank.cpp | 4 ++-- dlls/csx/source/rank.h | 7 +++++++ dlls/dod2/dodx/NRank.cpp | 4 ++-- dlls/dod2/dodx/dodx.h | 7 +++++++ dlls/tfc/tfcx/NRank.cpp | 4 ++-- dlls/tfc/tfcx/tfcx.h | 7 +++++++ dlls/ts/tsx/NRank.cpp | 4 ++-- dlls/ts/tsx/tsx.h | 7 +++++++ 8 files changed, 36 insertions(+), 8 deletions(-) diff --git a/dlls/csx/source/rank.cpp b/dlls/csx/source/rank.cpp index d20ae459..50524048 100755 --- a/dlls/csx/source/rank.cpp +++ b/dlls/csx/source/rank.cpp @@ -9,7 +9,7 @@ static cell AMX_NATIVE_CALL get_user_astats(AMX *amx, cell *params) /* 6 param * int index = params[1]; CHECK_PLAYER(index); int attacker = params[2]; - CHECK_PLAYER(attacker); + CHECK_PLAYERRANGE(attacker); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); if (pPlayer->attackers[attacker].hits){ cell *cpStats = MF_GetAmxAddr(amx,params[3]); @@ -36,7 +36,7 @@ static cell AMX_NATIVE_CALL get_user_vstats(AMX *amx, cell *params) /* 6 param * int index = params[1]; CHECK_PLAYER(index); int victim = params[2]; - CHECK_PLAYER(victim); + CHECK_PLAYERRANGE(victim); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); if (pPlayer->victims[victim].hits){ cell *cpStats = MF_GetAmxAddr(amx,params[3]); diff --git a/dlls/csx/source/rank.h b/dlls/csx/source/rank.h index b2564116..62db6cf5 100755 --- a/dlls/csx/source/rank.h +++ b/dlls/csx/source/rank.h @@ -125,6 +125,13 @@ bool isModuleActive(); } \ } +#define CHECK_PLAYERRANGE(x) \ + if (x > gpGlobals->maxClients || x < 0) \ + { \ + MF_LogError(amx, AMX_ERR_NATIVE, "Player out of range (%d)", x); \ + return 0; \ + } + #define CHECK_NONPLAYER(x) \ if (x < 1 || x <= gpGlobals->maxClients || x > gpGlobals->maxEntities) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Non-player entity %d out of range", x); \ diff --git a/dlls/dod2/dodx/NRank.cpp b/dlls/dod2/dodx/NRank.cpp index 512f1f31..4214eb45 100755 --- a/dlls/dod2/dodx/NRank.cpp +++ b/dlls/dod2/dodx/NRank.cpp @@ -37,7 +37,7 @@ static cell AMX_NATIVE_CALL get_user_astats(AMX *amx, cell *params) /* 6 param * int index = params[1]; CHECK_PLAYER(index); int attacker = params[2]; - CHECK_PLAYER(attacker); + CHECK_PLAYERRANGE(attacker); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); if (pPlayer->attackers[attacker].hits){ cell *cpStats = MF_GetAmxAddr(amx,params[3]); @@ -64,7 +64,7 @@ static cell AMX_NATIVE_CALL get_user_vstats(AMX *amx, cell *params) /* 6 param * int index = params[1]; CHECK_PLAYER(index); int victim = params[2]; - CHECK_PLAYER(victim); + CHECK_PLAYERRANGE(victim); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); if (pPlayer->victims[victim].hits){ cell *cpStats = MF_GetAmxAddr(amx,params[3]); diff --git a/dlls/dod2/dodx/dodx.h b/dlls/dod2/dodx/dodx.h index 1b90cfa3..2246097b 100755 --- a/dlls/dod2/dodx/dodx.h +++ b/dlls/dod2/dodx/dodx.h @@ -140,6 +140,13 @@ edict_t *FindEntityByClassname(edict_t *pentStart, const char *szName); } \ } +#define CHECK_PLAYERRANGE(x) \ + if (x > gpGlobals->maxClients || x < 0) \ + { \ + MF_LogError(amx, AMX_ERR_NATIVE, "Player out of range (%d)", x); \ + return 0; \ + } + #define CHECK_NONPLAYER(x) \ if (x < 1 || x <= gpGlobals->maxClients || x > gpGlobals->maxEntities) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Non-player entity %d out of range", x); \ diff --git a/dlls/tfc/tfcx/NRank.cpp b/dlls/tfc/tfcx/NRank.cpp index 9f070696..b7c8bf1c 100755 --- a/dlls/tfc/tfcx/NRank.cpp +++ b/dlls/tfc/tfcx/NRank.cpp @@ -38,7 +38,7 @@ static cell AMX_NATIVE_CALL get_user_astats(AMX *amx, cell *params) /* 6 param * int index = params[1]; CHECK_PLAYER(index); int attacker = params[2]; - CHECK_PLAYER(attacker); + CHECK_PLAYERRANGE(attacker); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); if (pPlayer->attackers[attacker].hits){ cell *cpStats = MF_GetAmxAddr(amx,params[3]); @@ -65,7 +65,7 @@ static cell AMX_NATIVE_CALL get_user_vstats(AMX *amx, cell *params) /* 6 param * int index = params[1]; CHECK_PLAYER(index); int victim = params[2]; - CHECK_PLAYER(victim); + CHECK_PLAYERRANGE(victim); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); if (pPlayer->victims[victim].hits){ cell *cpStats = MF_GetAmxAddr(amx,params[3]); diff --git a/dlls/tfc/tfcx/tfcx.h b/dlls/tfc/tfcx/tfcx.h index 0c4dc889..92f1afea 100755 --- a/dlls/tfc/tfcx/tfcx.h +++ b/dlls/tfc/tfcx/tfcx.h @@ -134,6 +134,13 @@ bool util_strncmp( const char *sz1, const char *sz2, int size); } \ } +#define CHECK_PLAYERRANGE(x) \ + if (x > gpGlobals->maxClients || x < 0) \ + { \ + MF_LogError(amx, AMX_ERR_NATIVE, "Player out of range (%d)", x); \ + return 0; \ + } + #define CHECK_NONPLAYER(x) \ if (x < 1 || x <= gpGlobals->maxClients || x > gpGlobals->maxEntities) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Non-player entity %d out of range", x); \ diff --git a/dlls/ts/tsx/NRank.cpp b/dlls/ts/tsx/NRank.cpp index 4cad1a89..0a5bb159 100755 --- a/dlls/ts/tsx/NRank.cpp +++ b/dlls/ts/tsx/NRank.cpp @@ -38,7 +38,7 @@ static cell AMX_NATIVE_CALL get_user_astats(AMX *amx, cell *params) /* 6 param * int index = params[1]; CHECK_PLAYER(index); int attacker = params[2]; - CHECK_PLAYER(attacker); + CHECK_PLAYERRANGE(attacker); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); if (pPlayer->attackers[attacker].hits){ cell *cpStats = MF_GetAmxAddr(amx,params[3]); @@ -65,7 +65,7 @@ static cell AMX_NATIVE_CALL get_user_vstats(AMX *amx, cell *params) /* 6 param * int index = params[1]; CHECK_PLAYER(index); int victim = params[2]; - CHECK_PLAYER(victim); + CHECK_PLAYERRANGE(victim); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); if (pPlayer->victims[victim].hits){ cell *cpStats = MF_GetAmxAddr(amx,params[3]); diff --git a/dlls/ts/tsx/tsx.h b/dlls/ts/tsx/tsx.h index 2d05888f..14e31ec5 100755 --- a/dlls/ts/tsx/tsx.h +++ b/dlls/ts/tsx/tsx.h @@ -148,6 +148,13 @@ bool ignoreBots (edict_t *pEnt, edict_t *pOther = NULL); } \ } +#define CHECK_PLAYERRANGE(x) \ + if (x > gpGlobals->maxClients || x < 0) \ + { \ + MF_LogError(amx, AMX_ERR_NATIVE, "Player out of range (%d)", x); \ + return 0; \ + } + #define GETEDICT(n) \ ((n >= 1 && n <= gpGlobals->maxClients) ? MF_GetPlayerEdict(n) : INDEXENT(n))