Reject droid move packets containing illegal movement coordinates.

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4321 4a71c877-e1ca-e34f-864e-861f7616d084
master
Per Inge Mathisen 2008-03-24 20:55:23 +00:00
parent f0dae06115
commit d7136d8290
1 changed files with 16 additions and 0 deletions

View File

@ -356,6 +356,8 @@ BOOL SendDroidMove(const DROID* psDroid, uint32_t x, uint32_t y, BOOL formation)
if (!bMultiPlayer) if (!bMultiPlayer)
return true; return true;
ASSERT(x > 0 && y > 0, "SendDroidMove: Invalid move order");
// Don't allow a move to happen at all if it is not our responsibility // Don't allow a move to happen at all if it is not our responsibility
if (!myResponsibility(psDroid->player)) if (!myResponsibility(psDroid->player))
{ {
@ -402,6 +404,12 @@ BOOL recvDroidMove()
NETend(); NETend();
if ((x == 0 && y == 0) || x > world_coord(mapWidth) || y > world_coord(mapHeight))
{
/* Probably an invalid droid position */
debug(LOG_ERROR, "Received an invalid droid position from %d", NETgetSource());
return false;
}
if (!IdToDroid(droid, player, &psDroid)) if (!IdToDroid(droid, player, &psDroid))
{ {
debug(LOG_ERROR, "recvDroidMove: Packet from %d refers to non-existent droid %d!", debug(LOG_ERROR, "recvDroidMove: Packet from %d refers to non-existent droid %d!",
@ -431,6 +439,8 @@ BOOL SendDroid(const DROID_TEMPLATE* pTemplate, uint32_t x, uint32_t y, uint8_t
if (!bMultiPlayer) if (!bMultiPlayer)
return true; return true;
ASSERT(x != 0 && y != 0, "SendDroid: Invalid droid coordinates");
// Dont send other droids during campaign setup // Dont send other droids during campaign setup
if (ingame.localJoiningInProgress) if (ingame.localJoiningInProgress)
{ {
@ -482,6 +492,12 @@ BOOL recvDroid()
} }
NETend(); NETend();
if ((pos.x == 0 && pos.y == 0) || pos.x > world_coord(mapWidth) || pos.y > world_coord(mapHeight))
{
debug(LOG_ERROR, "recvDroid: Received bad droid position (%d, %d) from %d", (int)pos.x, (int)pos.y, NETgetSource());
return false;
}
// If we can not find the template ask for the entire droid instead // If we can not find the template ask for the entire droid instead
if (!pT) if (!pT)
{ {