Add or adjust a bunch of safety checks (#433)

This commit is contained in:
Vincent Herbet 2018-08-26 17:18:39 +02:00 committed by GitHub
parent 8aeefc3fca
commit 9bcabfeb1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 156 additions and 86 deletions

View File

@ -214,7 +214,7 @@ static cell AMX_NATIVE_CALL console_print(AMX *amx, cell *params) /* 2 param */
{ {
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
if (pPlayer->ingame) if (pPlayer->ingame && !pPlayer->IsBot())
{ {
if (len > 126) // Client console truncates after byte 127. (126 + \n = 127) if (len > 126) // Client console truncates after byte 127. (126 + \n = 127)
{ {
@ -247,7 +247,7 @@ static cell AMX_NATIVE_CALL client_print(AMX *amx, cell *params) /* 3 param */
{ {
CPlayer *pPlayer = GET_PLAYER_POINTER_I(i); CPlayer *pPlayer = GET_PLAYER_POINTER_I(i);
if (pPlayer->ingame) if (pPlayer->ingame && !pPlayer->IsBot())
{ {
g_langMngr.SetDefLang(i); g_langMngr.SetDefLang(i);
msg = format_amxstring(amx, params, 3, len); msg = format_amxstring(amx, params, 3, len);
@ -280,7 +280,7 @@ static cell AMX_NATIVE_CALL client_print(AMX *amx, cell *params) /* 3 param */
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
if (pPlayer->ingame) if (pPlayer->ingame && !pPlayer->IsBot())
{ {
g_langMngr.SetDefLang(index); g_langMngr.SetDefLang(index);
@ -427,7 +427,7 @@ static cell AMX_NATIVE_CALL show_motd(AMX *amx, cell *params) /* 3 param */
{ {
CPlayer* pPlayer = GET_PLAYER_POINTER_I(i); CPlayer* pPlayer = GET_PLAYER_POINTER_I(i);
if (pPlayer->ingame) if (pPlayer->ingame && !pPlayer->IsBot())
UTIL_ShowMOTD(pPlayer->pEdict, sToShow, ilen, szHead); UTIL_ShowMOTD(pPlayer->pEdict, sToShow, ilen, szHead);
} }
} else { } else {
@ -444,7 +444,7 @@ static cell AMX_NATIVE_CALL show_motd(AMX *amx, cell *params) /* 3 param */
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
if (pPlayer->ingame) if (pPlayer->ingame && !pPlayer->IsBot())
UTIL_ShowMOTD(pPlayer->pEdict, sToShow, ilen, szHead); UTIL_ShowMOTD(pPlayer->pEdict, sToShow, ilen, szHead);
} }
@ -524,7 +524,7 @@ static cell AMX_NATIVE_CALL show_hudmessage(AMX *amx, cell *params) /* 2 param *
{ {
CPlayer *pPlayer = GET_PLAYER_POINTER_I(i); CPlayer *pPlayer = GET_PLAYER_POINTER_I(i);
if (pPlayer->ingame) if (pPlayer->ingame && !pPlayer->IsBot())
{ {
g_langMngr.SetDefLang(i); g_langMngr.SetDefLang(i);
message = UTIL_SplitHudMessage(format_amxstring(amx, params, 2, len)); message = UTIL_SplitHudMessage(format_amxstring(amx, params, 2, len));
@ -551,7 +551,7 @@ static cell AMX_NATIVE_CALL show_hudmessage(AMX *amx, cell *params) /* 2 param *
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
if (pPlayer->ingame) if (pPlayer->ingame && !pPlayer->IsBot())
{ {
if (aut) if (aut)
{ {
@ -787,22 +787,27 @@ static cell AMX_NATIVE_CALL is_user_alive(AMX *amx, cell *params) /* 1 param */
if (index < 1 || index > gpGlobals->maxClients) if (index < 1 || index > gpGlobals->maxClients)
{ {
return 0; return FALSE;
} }
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
if (!pPlayer->ingame)
{
return FALSE;
}
if (g_bmod_tfc) if (g_bmod_tfc)
{ {
edict_t *e = pPlayer->pEdict; edict_t *e = pPlayer->pEdict;
if (e->v.flags & FL_SPECTATOR || if (e->v.flags & FL_SPECTATOR ||
(!e->v.team || !e->v.playerclass)) (!e->v.team || !e->v.playerclass))
{ {
return 0; return FALSE;
} }
} }
return ((pPlayer->ingame && pPlayer->IsAlive()) ? 1 : 0); return pPlayer->IsAlive() ? TRUE : FALSE;
} }
static cell AMX_NATIVE_CALL get_amxx_verstring(AMX *amx, cell *params) /* 2 params */ static cell AMX_NATIVE_CALL get_amxx_verstring(AMX *amx, cell *params) /* 2 params */
@ -1106,6 +1111,12 @@ static cell AMX_NATIVE_CALL user_has_weapon(AMX *amx, cell *params)
} }
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
if (!pPlayer->ingame)
{
return 0;
}
edict_t *pEntity = pPlayer->pEdict; edict_t *pEntity = pPlayer->pEdict;
if (params[3] == -1) if (params[3] == -1)
@ -1344,6 +1355,8 @@ static cell AMX_NATIVE_CALL show_menu(AMX *amx, cell *params) /* 3 param */
} else { } else {
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
if (pPlayer->ingame)
{
pPlayer->keys = keys; pPlayer->keys = keys;
pPlayer->menu = menuid; pPlayer->menu = menuid;
pPlayer->vgui = false; pPlayer->vgui = false;
@ -1356,6 +1369,7 @@ static cell AMX_NATIVE_CALL show_menu(AMX *amx, cell *params) /* 3 param */
pPlayer->page = 0; pPlayer->page = 0;
UTIL_ShowMenu(pPlayer->pEdict, keys, time, sMenu, ilen); UTIL_ShowMenu(pPlayer->pEdict, keys, time, sMenu, ilen);
} }
}
return 1; return 1;
} }

View File

@ -87,6 +87,7 @@ void Client_TeamInfo(void* mValue)
case 1: case 1:
if (index < 1 || index > gpGlobals->maxClients) break; if (index < 1 || index > gpGlobals->maxClients) break;
char* msg = (char*)mValue; char* msg = (char*)mValue;
if (!msg) break;
g_players[index].team = msg; g_players[index].team = msg;
g_teamsIds.registerTeam(msg, -1); g_teamsIds.registerTeam(msg, -1);
g_players[index].teamId = g_teamsIds.findTeamId(msg); g_players[index].teamId = g_teamsIds.findTeamId(msg);

View File

@ -1434,8 +1434,15 @@ int C_Cmd_Argc(void)
// Only here we may find out who is an owner. // Only here we may find out who is an owner.
void C_SetModel(edict_t *e, const char *m) void C_SetModel(edict_t *e, const char *m)
{ {
if (e->v.owner && m[7]=='w' && m[8]=='_' && m[9]=='h') if (!m || strcmp(m, "models/w_hegrenade.mdl") != 0)
g_grenades.put(e, 1.75, 4, GET_PLAYER_POINTER(e->v.owner)); {
RETURN_META(MRES_IGNORED);
}
if (e->v.owner)
{
g_grenades.put(e, 1.75f, 4, GET_PLAYER_POINTER(e->v.owner));
}
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }

View File

@ -882,7 +882,7 @@ static cell AMX_NATIVE_CALL cs_set_user_model(AMX *amx, cell *params)
GET_OFFSET("CBasePlayer", m_modelIndexPlayer); GET_OFFSET("CBasePlayer", m_modelIndexPlayer);
char modelpath[260]; char modelpath[PLATFORM_MAX_PATH];
ke::SafeSprintf(modelpath, sizeof(modelpath), "models/player/%s/%s.mdl", newModel, newModel); ke::SafeSprintf(modelpath, sizeof(modelpath), "models/player/%s/%s.mdl", newModel, newModel);
auto modelIndex = 0; auto modelIndex = 0;

View File

@ -13,12 +13,13 @@
#include "amxxmodule.h" #include "amxxmodule.h"
#include <amtl/am-algorithm.h> #include <amtl/am-algorithm.h>
#include <amtl/am-string.h>
extern int MessageIdTextMsg; extern int MessageIdTextMsg;
bool UTIL_IsPlayer(edict_t *pPlayer) bool UTIL_IsPlayer(edict_t *pPlayer)
{ {
return strcmp(STRING(pPlayer->v.classname), "player") == 0; return pPlayer && strcmp(STRING(pPlayer->v.classname), "player") == 0;
} }
void UTIL_TextMsg_Generic(edict_t* pPlayer, const char* message) void UTIL_TextMsg_Generic(edict_t* pPlayer, const char* message)
@ -36,7 +37,7 @@ bool UTIL_CheckForPublic(const char *publicname)
int i = 0; int i = 0;
char blah[64]; char blah[64];
strncpy(blah, publicname, sizeof(blah) - 1); ke::SafeStrcpy(blah, sizeof(blah), publicname);
while ((amx = MF_GetScriptAmx(i++))) while ((amx = MF_GetScriptAmx(i++)))
{ {

View File

@ -49,6 +49,10 @@ void UTIL_StringToLower(const char *str, char *buffer, size_t maxlength);
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (not in-game)", x); \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (not in-game)", x); \
return 0; \ return 0; \
} \ } \
else if (!MF_GetPlayerEdict(x)->pvPrivateData) { \
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (no private data)", x); \
return 0; \
} \
} else { \ } else { \
if (x != 0 && FNullEnt(TypeConversion.id_to_edict(x))) { \ if (x != 0 && FNullEnt(TypeConversion.id_to_edict(x))) { \
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d", x); \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d", x); \
@ -62,8 +66,12 @@ void UTIL_StringToLower(const char *str, char *buffer, size_t maxlength);
MF_LogError(amx, AMX_ERR_NATIVE, "Player out of range (%d)", x); \ MF_LogError(amx, AMX_ERR_NATIVE, "Player out of range (%d)", x); \
return 0; \ return 0; \
} else { \ } else { \
if (!MF_IsPlayerIngame(x) || FNullEnt(MF_GetPlayerEdict(x))) { \ if (!MF_IsPlayerIngame(x)) { \
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d", x); \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (not in-game)", x); \
return 0; \
} \
else if (!MF_GetPlayerEdict(x)->pvPrivateData) { \
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (no private data)", x); \
return 0; \ return 0; \
} \ } \
} }

View File

@ -178,14 +178,18 @@ void PlayerPreThink_Post( edict_t *pEntity ) {
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }
void ServerDeactivate() { void ServerDeactivate()
{
int i; int i;
for( i = 1;i<=gpGlobals->maxClients; ++i){
CPlayer *pPlayer = GET_PLAYER_POINTER_I(i); for( i = 1; i <= gpGlobals->maxClients; ++i)
if (pPlayer->rank) pPlayer->Disconnect(); {
GET_PLAYER_POINTER_I(i)->Disconnect();
} }
if ( (g_rank.getRankNum() >= (int)csstats_maxsize->value) || ((int)csstats_reset->value == 1 ) ) {
CVAR_SET_FLOAT("csstats_reset",0.0); if (static_cast<int>(csstats_maxsize->value) <= 0 || g_rank.getRankNum() >= static_cast<int>(csstats_maxsize->value) || static_cast<int>(csstats_reset->value) != 0)
{
CVAR_SET_FLOAT("csstats_reset", 0.0f);
g_rank.clear(); // clear before save to file g_rank.clear(); // clear before save to file
} }
g_rank.saveRank( MF_BuildPathname("%s",get_localinfo("csstats")) ); g_rank.saveRank( MF_BuildPathname("%s",get_localinfo("csstats")) );
@ -197,27 +201,26 @@ void ServerDeactivate() {
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }
BOOL ClientConnect_Post( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] ){ BOOL ClientConnect_Post( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128])
{
CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity); CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity);
if (pPlayer->pEdict == NULL)
{
pPlayer->Init(ENTINDEX(pEntity), pEntity);
}
pPlayer->Connect(pszAddress); pPlayer->Connect(pszAddress);
RETURN_META_VALUE(MRES_IGNORED, TRUE); RETURN_META_VALUE(MRES_IGNORED, TRUE);
} }
void ClientDisconnect( edict_t *pEntity ) { void ClientDisconnect( edict_t *pEntity )
CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity); {
if (pPlayer->rank) pPlayer->Disconnect(); GET_PLAYER_POINTER(pEntity)->Disconnect();
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }
void ClientPutInServer_Post( edict_t *pEntity ) { void ClientPutInServer_Post( edict_t *pEntity )
{
GET_PLAYER_POINTER(pEntity)->PutInServer(); GET_PLAYER_POINTER(pEntity)->PutInServer();
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }

View File

@ -456,6 +456,13 @@ static cell AMX_NATIVE_CALL set_view(AMX *amx, cell *params) {
plinfo[iIndex].iViewType = CAMERA_3RDPERSON; plinfo[iIndex].iViewType = CAMERA_3RDPERSON;
pNewCamera = CREATE_NAMED_ENTITY(MAKE_STRING("info_target")); pNewCamera = CREATE_NAMED_ENTITY(MAKE_STRING("info_target"));
if (!pNewCamera)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Could not create camera entity.");
return 0;
}
pNewCamera->v.classname = MAKE_STRING("VexdCam"); pNewCamera->v.classname = MAKE_STRING("VexdCam");
SET_MODEL(pNewCamera, "models/rpgrocket.mdl"); SET_MODEL(pNewCamera, "models/rpgrocket.mdl");
@ -486,6 +493,13 @@ static cell AMX_NATIVE_CALL set_view(AMX *amx, cell *params) {
plinfo[iIndex].iViewType = CAMERA_UPLEFT; plinfo[iIndex].iViewType = CAMERA_UPLEFT;
pNewCamera = CREATE_NAMED_ENTITY(MAKE_STRING("info_target")); pNewCamera = CREATE_NAMED_ENTITY(MAKE_STRING("info_target"));
if (!pNewCamera)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Could not create camera entity.");
return 0;
}
pNewCamera->v.classname = MAKE_STRING("VexdCam"); pNewCamera->v.classname = MAKE_STRING("VexdCam");
SET_MODEL(pNewCamera, "models/rpgrocket.mdl"); SET_MODEL(pNewCamera, "models/rpgrocket.mdl");
@ -516,6 +530,13 @@ static cell AMX_NATIVE_CALL set_view(AMX *amx, cell *params) {
plinfo[iIndex].iViewType = CAMERA_TOPDOWN; plinfo[iIndex].iViewType = CAMERA_TOPDOWN;
pNewCamera = CREATE_NAMED_ENTITY(MAKE_STRING("info_target")); pNewCamera = CREATE_NAMED_ENTITY(MAKE_STRING("info_target"));
if (!pNewCamera)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Could not create camera entity.");
return 0;
}
pNewCamera->v.classname = MAKE_STRING("VexdCam"); pNewCamera->v.classname = MAKE_STRING("VexdCam");
SET_MODEL(pNewCamera, "models/rpgrocket.mdl"); SET_MODEL(pNewCamera, "models/rpgrocket.mdl");

View File

@ -50,6 +50,16 @@
#define CHECK_ENTITY(x) if (x != 0 && (FNullEnt(TypeConversion.id_to_edict(x)) || x < 0 || x > gpGlobals->maxEntities)) { MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity"); return 0; } #define CHECK_ENTITY(x) if (x != 0 && (FNullEnt(TypeConversion.id_to_edict(x)) || x < 0 || x > gpGlobals->maxEntities)) { MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity"); return 0; }
#define CHECK_OFFSET(x) if (x < 0) { MF_LogError(amx, AMX_ERR_NATIVE, "Invalid offset"); return 0; } #define CHECK_OFFSET(x) if (x < 0) { MF_LogError(amx, AMX_ERR_NATIVE, "Invalid offset"); return 0; }
#define CHECK_ENTITY_PDATA(x) \
if (FNullEnt(TypeConversion.id_to_edict(x))) { \
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d", x); \
return 0; \
} \
else if (!TypeConversion.id_to_edict(x)->pvPrivateData) { \
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d (no private data)", x); \
return 0; \
}
extern AMX_NATIVE_INFO engfunc_natives[]; extern AMX_NATIVE_INFO engfunc_natives[];
extern AMX_NATIVE_INFO dllfunc_natives[]; extern AMX_NATIVE_INFO dllfunc_natives[];

View File

@ -86,7 +86,7 @@ static cell AMX_NATIVE_CALL set_tr(AMX *amx, cell *params)
case TR_pHit: case TR_pHit:
{ {
e = TypeConversion.id_to_edict(*ptr); e = TypeConversion.id_to_edict(*ptr);
if (!e || FNullEnt(e)) if (*ptr != -1 && FNullEnt(e))
return 0; //TODO: return error return 0; //TODO: return error
gfm_tr->pHit = e; gfm_tr->pHit = e;
return 1; return 1;
@ -167,7 +167,7 @@ static cell AMX_NATIVE_CALL get_tr(AMX *amx, cell *params)
} }
case TR_pHit: case TR_pHit:
{ {
if (gfm_tr->pHit == NULL || FNullEnt(gfm_tr->pHit)) if (FNullEnt(gfm_tr->pHit))
return -1; return -1;
return ENTINDEX(gfm_tr->pHit); return ENTINDEX(gfm_tr->pHit);
break; break;

View File

@ -99,7 +99,7 @@ static cell AMX_NATIVE_CALL set_tr2(AMX *amx, cell *params)
case TR_pHit: case TR_pHit:
{ {
edict_t *e = TypeConversion.id_to_edict(*ptr); edict_t *e = TypeConversion.id_to_edict(*ptr);
if (!e || FNullEnt(e)) if (*ptr != -1 && FNullEnt(e))
return 0; //TODO: return error return 0; //TODO: return error
tr->pHit = e; tr->pHit = e;
return 1; return 1;
@ -187,7 +187,7 @@ static cell AMX_NATIVE_CALL get_tr2(AMX *amx, cell *params)
} }
case TR_pHit: case TR_pHit:
{ {
if (tr->pHit == NULL || FNullEnt(tr->pHit)) if (FNullEnt(tr->pHit))
return -1; return -1;
return ENTINDEX(tr->pHit); return ENTINDEX(tr->pHit);
break; break;

View File

@ -18,7 +18,7 @@ static cell AMX_NATIVE_CALL copy_infokey_buffer(AMX *amx, cell *params)
{ {
char *infobuffer = reinterpret_cast<char *>(params[1]); char *infobuffer = reinterpret_cast<char *>(params[1]);
return MF_SetAmxString(amx, params[2], infobuffer, params[3]); return MF_SetAmxString(amx, params[2], infobuffer ? infobuffer : "", params[3]);
} }
// lookup_sequence(entid, "sequence name", &Float:framerate = 0.0, &bool:loops = false, &Float:groundspeed = 0.0); // lookup_sequence(entid, "sequence name", &Float:framerate = 0.0, &bool:loops = false, &Float:groundspeed = 0.0);

View File

@ -32,18 +32,18 @@
//implement these with setjmp later. //implement these with setjmp later.
bool IsBadReadPtr(void *l, size_t size) bool IsBadReadPtr(void *l, size_t size)
{ {
return false; return l ? false : true;
} }
bool IsBadWritePtr(void *l, size_t size) bool IsBadWritePtr(void *l, size_t size)
{ {
return false; return l ? false : true;
} }
#endif #endif
static cell AMX_NATIVE_CALL set_pdata_int(AMX *amx, cell *params) static cell AMX_NATIVE_CALL set_pdata_int(AMX *amx, cell *params)
{ {
int index=params[1]; int index=params[1];
CHECK_ENTITY(index); CHECK_ENTITY_PDATA(index);
int iOffset=params[2]; int iOffset=params[2];
CHECK_OFFSET(iOffset); CHECK_OFFSET(iOffset);
@ -65,7 +65,7 @@ static cell AMX_NATIVE_CALL set_pdata_int(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL get_pdata_int(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_pdata_int(AMX *amx, cell *params)
{ {
int index=params[1]; int index=params[1];
CHECK_ENTITY(index); CHECK_ENTITY_PDATA(index);
int iOffset=params[2]; int iOffset=params[2];
CHECK_OFFSET(iOffset); CHECK_OFFSET(iOffset);
@ -87,7 +87,7 @@ static cell AMX_NATIVE_CALL get_pdata_int(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL set_pdata_float(AMX *amx, cell *params) static cell AMX_NATIVE_CALL set_pdata_float(AMX *amx, cell *params)
{ {
int index=params[1]; int index=params[1];
CHECK_ENTITY(index); CHECK_ENTITY_PDATA(index);
int iOffset=params[2]; int iOffset=params[2];
CHECK_OFFSET(iOffset); CHECK_OFFSET(iOffset);
@ -109,7 +109,7 @@ static cell AMX_NATIVE_CALL set_pdata_float(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL get_pdata_float(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_pdata_float(AMX *amx, cell *params)
{ {
int index=params[1]; int index=params[1];
CHECK_ENTITY(index); CHECK_ENTITY_PDATA(index);
int iOffset=params[2]; int iOffset=params[2];
CHECK_OFFSET(iOffset); CHECK_OFFSET(iOffset);
@ -130,7 +130,7 @@ static cell AMX_NATIVE_CALL get_pdata_float(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL get_pdata_string(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_pdata_string(AMX *amx, cell *params)
{ {
int index=params[1]; int index=params[1];
CHECK_ENTITY(index); CHECK_ENTITY_PDATA(index);
int iOffset=params[2]; int iOffset=params[2];
CHECK_OFFSET(iOffset); CHECK_OFFSET(iOffset);
@ -167,7 +167,7 @@ static cell AMX_NATIVE_CALL get_pdata_string(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL set_pdata_string(AMX *amx, cell *params) static cell AMX_NATIVE_CALL set_pdata_string(AMX *amx, cell *params)
{ {
int index=params[1]; int index=params[1];
CHECK_ENTITY(index); CHECK_ENTITY_PDATA(index);
int iOffset=params[2]; int iOffset=params[2];
CHECK_OFFSET(iOffset); CHECK_OFFSET(iOffset);
@ -192,22 +192,27 @@ static cell AMX_NATIVE_CALL set_pdata_string(AMX *amx, cell *params)
szData = get_pdata_direct<char*>(pEdict, iOffset); szData = get_pdata_direct<char*>(pEdict, iOffset);
if (IsBadWritePtr(szData, 1)) if (IsBadWritePtr(szData, 1))
return 0; return 0;
strcpy(szData, data);
} else { } else {
szData = get_pdata<char*>(pEdict, iOffset); szData = get_pdata<char*>(pEdict, iOffset);
if (IsBadWritePtr(szData, 1)) if (IsBadWritePtr(szData, 1))
return 0; return 0;
if (len > static_cast<int>(strlen(szData)))
{
if (params[4] == 1) if (params[4] == 1)
{ {
free(szData); free(szData);
szData = (char *)malloc(len + 1); szData = (char *)malloc(len + 1);
} else if (params[4] == 2) { }
delete [] szData; else if (params[4] == 2) {
delete[] szData;
szData = new char[len + 1]; szData = new char[len + 1];
} }
strcpy(szData, data);
set_pdata<char*>(pEdict, iOffset, szData); set_pdata<char*>(pEdict, iOffset, szData);
} }
}
strncopy(szData, data, len + 1);
return 1; return 1;
} }
@ -215,7 +220,7 @@ static cell AMX_NATIVE_CALL set_pdata_string(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL get_pdata_ent(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_pdata_ent(AMX *amx, cell *params)
{ {
int index=params[1]; int index=params[1];
CHECK_ENTITY(index); CHECK_ENTITY_PDATA(index);
int iOffset=params[2]; int iOffset=params[2];
CHECK_OFFSET(iOffset); CHECK_OFFSET(iOffset);
@ -256,7 +261,7 @@ static cell AMX_NATIVE_CALL get_pdata_ent(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL set_pdata_ent(AMX *amx, cell *params) static cell AMX_NATIVE_CALL set_pdata_ent(AMX *amx, cell *params)
{ {
int index = params[1]; int index = params[1];
CHECK_ENTITY(index); CHECK_ENTITY_PDATA(index);
int offset = params[2]; int offset = params[2];
CHECK_OFFSET(offset); CHECK_OFFSET(offset);
@ -282,7 +287,7 @@ static cell AMX_NATIVE_CALL set_pdata_ent(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL get_pdata_bool(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_pdata_bool(AMX *amx, cell *params)
{ {
int index = params[1]; int index = params[1];
CHECK_ENTITY(index); CHECK_ENTITY_PDATA(index);
int offset = params[2]; int offset = params[2];
CHECK_OFFSET(offset); CHECK_OFFSET(offset);
@ -303,7 +308,7 @@ static cell AMX_NATIVE_CALL get_pdata_bool(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL set_pdata_bool(AMX *amx, cell *params) static cell AMX_NATIVE_CALL set_pdata_bool(AMX *amx, cell *params)
{ {
int index = params[1]; int index = params[1];
CHECK_ENTITY(index); CHECK_ENTITY_PDATA(index);
int offset = params[2]; int offset = params[2];
CHECK_OFFSET(offset); CHECK_OFFSET(offset);
@ -328,7 +333,7 @@ static cell AMX_NATIVE_CALL set_pdata_bool(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL get_pdata_byte(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_pdata_byte(AMX *amx, cell *params)
{ {
int index = params[1]; int index = params[1];
CHECK_ENTITY(index); CHECK_ENTITY_PDATA(index);
int offset = params[2]; int offset = params[2];
CHECK_OFFSET(offset); CHECK_OFFSET(offset);
@ -349,7 +354,7 @@ static cell AMX_NATIVE_CALL get_pdata_byte(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL set_pdata_byte(AMX *amx, cell *params) static cell AMX_NATIVE_CALL set_pdata_byte(AMX *amx, cell *params)
{ {
int index = params[1]; int index = params[1];
CHECK_ENTITY(index); CHECK_ENTITY_PDATA(index);
int offset = params[2]; int offset = params[2];
CHECK_OFFSET(offset); CHECK_OFFSET(offset);
@ -374,7 +379,7 @@ static cell AMX_NATIVE_CALL set_pdata_byte(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL get_pdata_short(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_pdata_short(AMX *amx, cell *params)
{ {
int index = params[1]; int index = params[1];
CHECK_ENTITY(index); CHECK_ENTITY_PDATA(index);
int offset = params[2]; int offset = params[2];
CHECK_OFFSET(offset); CHECK_OFFSET(offset);
@ -395,7 +400,7 @@ static cell AMX_NATIVE_CALL get_pdata_short(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL set_pdata_short(AMX *amx, cell *params) static cell AMX_NATIVE_CALL set_pdata_short(AMX *amx, cell *params)
{ {
int index = params[1]; int index = params[1];
CHECK_ENTITY(index); CHECK_ENTITY_PDATA(index);
int offset = params[2]; int offset = params[2];
CHECK_OFFSET(offset); CHECK_OFFSET(offset);
@ -420,7 +425,7 @@ static cell AMX_NATIVE_CALL set_pdata_short(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL get_pdata_vector(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_pdata_vector(AMX *amx, cell *params)
{ {
int index = params[1]; int index = params[1];
CHECK_ENTITY(index); CHECK_ENTITY_PDATA(index);
int offset = params[2]; int offset = params[2];
CHECK_OFFSET(offset); CHECK_OFFSET(offset);
@ -449,7 +454,7 @@ static cell AMX_NATIVE_CALL get_pdata_vector(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL set_pdata_vector(AMX *amx, cell *params) static cell AMX_NATIVE_CALL set_pdata_vector(AMX *amx, cell *params)
{ {
int index = params[1]; int index = params[1];
CHECK_ENTITY(index); CHECK_ENTITY_PDATA(index);
int offset = params[2]; int offset = params[2];
CHECK_OFFSET(offset); CHECK_OFFSET(offset);
@ -476,7 +481,7 @@ static cell AMX_NATIVE_CALL set_pdata_vector(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL get_pdata_ehandle(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_pdata_ehandle(AMX *amx, cell *params)
{ {
int index = params[1]; int index = params[1];
CHECK_ENTITY(index); CHECK_ENTITY_PDATA(index);
int offset = params[2]; int offset = params[2];
CHECK_OFFSET(offset); CHECK_OFFSET(offset);
@ -524,7 +529,7 @@ static cell AMX_NATIVE_CALL get_pdata_ehandle(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL set_pdata_ehandle(AMX *amx, cell *params) static cell AMX_NATIVE_CALL set_pdata_ehandle(AMX *amx, cell *params)
{ {
int index = params[1]; int index = params[1];
CHECK_ENTITY(index); CHECK_ENTITY_PDATA(index);
int offset = params[2]; int offset = params[2];
CHECK_OFFSET(offset); CHECK_OFFSET(offset);

View File

@ -18,7 +18,7 @@
static cell AMX_NATIVE_CALL get_ent_data(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_ent_data(AMX *amx, cell *params)
{ {
int entity = params[1]; int entity = params[1];
CHECK_ENTITY(entity); CHECK_ENTITY_PDATA(entity);
TypeDescription data; TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig); GET_TYPE_DESCRIPTION(2, data, CommonConfig);
@ -33,7 +33,7 @@ static cell AMX_NATIVE_CALL get_ent_data(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL set_ent_data(AMX *amx, cell *params) static cell AMX_NATIVE_CALL set_ent_data(AMX *amx, cell *params)
{ {
int entity = params[1]; int entity = params[1];
CHECK_ENTITY(entity); CHECK_ENTITY_PDATA(entity);
TypeDescription data; TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig); GET_TYPE_DESCRIPTION(2, data, CommonConfig);
@ -57,7 +57,7 @@ static cell AMX_NATIVE_CALL set_ent_data(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL get_ent_data_float(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_ent_data_float(AMX *amx, cell *params)
{ {
int entity = params[1]; int entity = params[1];
CHECK_ENTITY(entity); CHECK_ENTITY_PDATA(entity);
TypeDescription data; TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig); GET_TYPE_DESCRIPTION(2, data, CommonConfig);
@ -72,7 +72,7 @@ static cell AMX_NATIVE_CALL get_ent_data_float(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL set_ent_data_float(AMX *amx, cell *params) static cell AMX_NATIVE_CALL set_ent_data_float(AMX *amx, cell *params)
{ {
int entity = params[1]; int entity = params[1];
CHECK_ENTITY(entity); CHECK_ENTITY_PDATA(entity);
TypeDescription data; TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig); GET_TYPE_DESCRIPTION(2, data, CommonConfig);
@ -90,7 +90,7 @@ static cell AMX_NATIVE_CALL set_ent_data_float(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL get_ent_data_vector(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_ent_data_vector(AMX *amx, cell *params)
{ {
int entity = params[1]; int entity = params[1];
CHECK_ENTITY(entity); CHECK_ENTITY_PDATA(entity);
TypeDescription data; TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig); GET_TYPE_DESCRIPTION(2, data, CommonConfig);
@ -107,7 +107,7 @@ static cell AMX_NATIVE_CALL get_ent_data_vector(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL set_ent_data_vector(AMX *amx, cell *params) static cell AMX_NATIVE_CALL set_ent_data_vector(AMX *amx, cell *params)
{ {
int entity = params[1]; int entity = params[1];
CHECK_ENTITY(entity); CHECK_ENTITY_PDATA(entity);
TypeDescription data; TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig); GET_TYPE_DESCRIPTION(2, data, CommonConfig);
@ -125,7 +125,7 @@ static cell AMX_NATIVE_CALL set_ent_data_vector(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL get_ent_data_entity(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_ent_data_entity(AMX *amx, cell *params)
{ {
int entity = params[1]; int entity = params[1];
CHECK_ENTITY(entity); CHECK_ENTITY_PDATA(entity);
TypeDescription data; TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig); GET_TYPE_DESCRIPTION(2, data, CommonConfig);
@ -142,7 +142,7 @@ static cell AMX_NATIVE_CALL set_ent_data_entity(AMX *amx, cell *params)
int entity = params[1]; int entity = params[1];
int value = params[4]; int value = params[4];
CHECK_ENTITY(entity); CHECK_ENTITY_PDATA(entity);
if (value != -1) if (value != -1)
{ {
@ -165,7 +165,7 @@ static cell AMX_NATIVE_CALL set_ent_data_entity(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL get_ent_data_string(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_ent_data_string(AMX *amx, cell *params)
{ {
int entity = params[1]; int entity = params[1];
CHECK_ENTITY(entity); CHECK_ENTITY_PDATA(entity);
TypeDescription data; TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig); GET_TYPE_DESCRIPTION(2, data, CommonConfig);
@ -190,7 +190,7 @@ static cell AMX_NATIVE_CALL get_ent_data_string(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL set_ent_data_string(AMX *amx, cell *params) static cell AMX_NATIVE_CALL set_ent_data_string(AMX *amx, cell *params)
{ {
int entity = params[1]; int entity = params[1];
CHECK_ENTITY(entity); CHECK_ENTITY_PDATA(entity);
TypeDescription data; TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig); GET_TYPE_DESCRIPTION(2, data, CommonConfig);