Prevent out of bounds access of player stat arrays.

In the 2.3 netcode, we use player 9 for features, while we only have stats for
players 0-7. Fixes #2029 and probably a truckoad of other random problems.

git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@11323 4a71c877-e1ca-e34f-864e-861f7616d084
master
Christian Ohm 2010-07-31 23:56:18 +00:00 committed by Git SVN Gateway
parent 943af316ec
commit 324722fc93
1 changed files with 36 additions and 20 deletions

View File

@ -52,6 +52,11 @@ BOOL setMultiStats(SDWORD player, PLAYERSTATS plStats, BOOL bLocal)
{
uint32_t playerIndex = (uint32_t)player;
if (playerIndex >= MAX_PLAYERS)
{
return true;
}
// First copy over the data into our local array
memcpy(&playerStats[playerIndex], &plStats, sizeof(plStats));
@ -87,6 +92,11 @@ void recvMultiStats()
// update the stats
NETuint32_t(&playerIndex);
if (playerIndex >= MAX_PLAYERS)
{
return;
}
// we don't what to update ourselves, we already know our score (FIXME: rewrite setMultiStats())
if (!myResponsibility(playerIndex))
{
@ -200,30 +210,35 @@ void updateMultiStatsDamage(UDWORD attacker, UDWORD defender, UDWORD inflicted)
}
// FIXME: Why in the world are we using two different structs for stats when we can use only one?
// Host controls self + AI, so update the scores for them as well.
if(myResponsibility(attacker) && NetPlay.bComms)
if (attacker < MAX_PLAYERS)
{
if (myResponsibility(attacker) && NetPlay.bComms)
{
st = getMultiStats(attacker); // get stats
if(NetPlay.bComms)
if (NetPlay.bComms)
{
st.scoreToAdd += (2*inflicted);
st.scoreToAdd += (2 * inflicted);
}
else
{
st.recentScore += (2*inflicted);
st.recentScore += (2 * inflicted);
}
setMultiStats(attacker, st, true);
}
else
{
ingame.skScores[attacker][0] += (2*inflicted); // increment skirmish players rough score.
ingame.skScores[attacker][0] += (2 * inflicted); // increment skirmish players rough score.
}
}
// FIXME: Why in the world are we using two different structs for stats when we can use only one?
// Host controls self + AI, so update the scores for them as well.
if(myResponsibility(defender) && NetPlay.bComms)
if (defender < MAX_PLAYERS)
{
if (myResponsibility(defender) && NetPlay.bComms)
{
st = getMultiStats(defender); // get stats
if(NetPlay.bComms)
if (NetPlay.bComms)
{
st.scoreToAdd -= inflicted;
}
@ -237,6 +252,7 @@ void updateMultiStatsDamage(UDWORD attacker, UDWORD defender, UDWORD inflicted)
{
ingame.skScores[defender][0] -= inflicted; // increment skirmish players rough score.
}
}
}
// update games played.