Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
GOTBLOCKS & DELETEBLOCKS: test packet size only once
  • Loading branch information
nerzhul committed Feb 23, 2016
1 parent f3f4af3 commit 1474254
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/network/serverpackethandler.cpp
Expand Up @@ -762,14 +762,14 @@ void Server::handleCommand_GotBlocks(NetworkPacket* pkt)

RemoteClient *client = getClient(pkt->getPeerId());

for (u16 i = 0; i < count; i++) {
if ((s16)pkt->getSize() < 1 + (i + 1) * 6)
throw con::InvalidIncomingDataException
if ((s16)pkt->getSize() < 1 + (int)count * 6) {
throw con::InvalidIncomingDataException
("GOTBLOCKS length is too short");
v3s16 p;
}

for (u16 i = 0; i < count; i++) {
v3s16 p;
*pkt >> p;

client->GotBlock(p);
}
}
Expand Down Expand Up @@ -865,13 +865,14 @@ void Server::handleCommand_DeletedBlocks(NetworkPacket* pkt)

RemoteClient *client = getClient(pkt->getPeerId());

for (u16 i = 0; i < count; i++) {
if ((s16)pkt->getSize() < 1 + (i + 1) * 6)
throw con::InvalidIncomingDataException
if ((s16)pkt->getSize() < 1 + (int)count * 6) {
throw con::InvalidIncomingDataException
("DELETEDBLOCKS length is too short");
}

for (u16 i = 0; i < count; i++) {
v3s16 p;
*pkt >> p;

client->SetBlockNotSent(p);
}
}
Expand Down

0 comments on commit 1474254

Please sign in to comment.