From: nerzhul Date: Tue, 23 Feb 2016 09:58:13 +0000 (+0100) Subject: GOTBLOCKS & DELETEBLOCKS: test packet size only once X-Git-Tag: 0.4.14~238 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=refs%2Fpull%2F3771%2Fhead;p=oweals%2Fminetest.git GOTBLOCKS & DELETEBLOCKS: test packet size only once --- diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index 7e348a94d..ef99a634f 100644 --- a/src/network/serverpackethandler.cpp +++ b/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); } }