Skip to content
Permalink
Browse files

GOTBLOCKS & DELETEBLOCKS: test packet size only once

  • Loading branch information
nerzhul committed Feb 23, 2016
1 parent f3f4af3 commit 147425483a9e1afa2a2a4d9c0d5fa8b68d105644
Showing with 10 additions and 9 deletions.
  1. +10 −9 src/network/serverpackethandler.cpp
@@ -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);
}
}
@@ -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);
}
}

0 comments on commit 1474254

Please sign in to comment.