Skip to content

Commit 1474254

Browse files
committedFeb 23, 2016
GOTBLOCKS & DELETEBLOCKS: test packet size only once
1 parent f3f4af3 commit 1474254

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed
 

‎src/network/serverpackethandler.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -762,14 +762,14 @@ void Server::handleCommand_GotBlocks(NetworkPacket* pkt)
762762

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

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

770+
for (u16 i = 0; i < count; i++) {
771+
v3s16 p;
771772
*pkt >> p;
772-
773773
client->GotBlock(p);
774774
}
775775
}
@@ -865,13 +865,14 @@ void Server::handleCommand_DeletedBlocks(NetworkPacket* pkt)
865865

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

868-
for (u16 i = 0; i < count; i++) {
869-
if ((s16)pkt->getSize() < 1 + (i + 1) * 6)
870-
throw con::InvalidIncomingDataException
868+
if ((s16)pkt->getSize() < 1 + (int)count * 6) {
869+
throw con::InvalidIncomingDataException
871870
("DELETEDBLOCKS length is too short");
871+
}
872+
873+
for (u16 i = 0; i < count; i++) {
872874
v3s16 p;
873875
*pkt >> p;
874-
875876
client->SetBlockNotSent(p);
876877
}
877878
}

0 commit comments

Comments
 (0)