From 6e340f9a5b185b58b80063655cd4cffd463b707c Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Wed, 7 Jun 2017 19:02:01 -0500 Subject: [PATCH] Don't use uninitialized ps from BotAI_GetClientState If BotAI_GetPlayerState returns qfalse, ps is untouched and in some cases means uninitialized. So don't use it if not valid. --- code/game/ai_chat.c | 12 ++++-------- code/game/ai_dmq3.c | 5 ++++- code/game/ai_main.c | 6 ++++-- code/game/ai_team.c | 8 ++++++-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/code/game/ai_chat.c b/code/game/ai_chat.c index ecb0b9be..a65875ff 100644 --- a/code/game/ai_chat.c +++ b/code/game/ai_chat.c @@ -100,8 +100,7 @@ int BotIsFirstInRankings(bot_state_t *bs) { //skip spectators if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue; // - BotAI_GetClientState(i, &ps); - if (score < ps.persistant[PERS_SCORE]) return qfalse; + if (BotAI_GetClientState(i, &ps) && score < ps.persistant[PERS_SCORE]) return qfalse; } return qtrue; } @@ -124,8 +123,7 @@ int BotIsLastInRankings(bot_state_t *bs) { //skip spectators if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue; // - BotAI_GetClientState(i, &ps); - if (score > ps.persistant[PERS_SCORE]) return qfalse; + if (BotAI_GetClientState(i, &ps) && score > ps.persistant[PERS_SCORE]) return qfalse; } return qtrue; } @@ -150,8 +148,7 @@ char *BotFirstClientInRankings(void) { //skip spectators if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue; // - BotAI_GetClientState(i, &ps); - if (ps.persistant[PERS_SCORE] > bestscore) { + if (BotAI_GetClientState(i, &ps) && ps.persistant[PERS_SCORE] > bestscore) { bestscore = ps.persistant[PERS_SCORE]; bestclient = i; } @@ -180,8 +177,7 @@ char *BotLastClientInRankings(void) { //skip spectators if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue; // - BotAI_GetClientState(i, &ps); - if (ps.persistant[PERS_SCORE] < worstscore) { + if (BotAI_GetClientState(i, &ps) && ps.persistant[PERS_SCORE] < worstscore) { worstscore = ps.persistant[PERS_SCORE]; bestclient = i; } diff --git a/code/game/ai_dmq3.c b/code/game/ai_dmq3.c index 6de1117b..3cc61f22 100644 --- a/code/game/ai_dmq3.c +++ b/code/game/ai_dmq3.c @@ -206,7 +206,10 @@ qboolean EntityIsDead(aas_entityinfo_t *entinfo) { if (entinfo->number >= 0 && entinfo->number < MAX_CLIENTS) { //retrieve the current client state - BotAI_GetClientState( entinfo->number, &ps ); + if (!BotAI_GetClientState(entinfo->number, &ps)) { + return qfalse; + } + if (ps.pm_type != PM_NORMAL) return qtrue; } return qfalse; diff --git a/code/game/ai_main.c b/code/game/ai_main.c index a01e1530..907a161d 100644 --- a/code/game/ai_main.c +++ b/code/game/ai_main.c @@ -990,8 +990,10 @@ int BotAI(int client, float thinktime) { } //retrieve the current client state - BotAI_GetClientState( client, &bs->cur_ps ); - + if (!BotAI_GetClientState(client, &bs->cur_ps)) { + BotAI_Print(PRT_FATAL, "BotAI: failed to get player state for player %d\n", client); + return qfalse; + } //retrieve any waiting server commands while( trap_BotGetServerCommand(client, buf, sizeof(buf)) ) { //have buf point to the command and args to the command arguments diff --git a/code/game/ai_team.c b/code/game/ai_team.c index 6176bd55..95b445cd 100644 --- a/code/game/ai_team.c +++ b/code/game/ai_team.c @@ -108,8 +108,12 @@ int BotClientTravelTimeToGoal(int client, bot_goal_t *goal) { playerState_t ps; int areanum; - BotAI_GetClientState(client, &ps); - areanum = BotPointAreaNum(ps.origin); + if (BotAI_GetClientState(client, &ps)) { + areanum = BotPointAreaNum(ps.origin); + } else { + areanum = 0; + } + if (!areanum) return 1; return trap_AAS_AreaTravelTimeToGoalArea(areanum, ps.origin, goal->areanum, TFL_DEFAULT); }