Codechange: move more logic about packet size validity and reading into Packet

This commit is contained in:
Rubidium
2021-04-18 09:01:27 +02:00
committed by rubidium42
parent 470d8b6637
commit c545cc9d70
4 changed files with 29 additions and 13 deletions

View File

@@ -134,14 +134,14 @@ void NetworkUDPSocketHandler::ReceivePackets()
#endif
NetworkAddress address(client_addr, client_len);
p.PrepareToRead();
/* If the size does not match the packet must be corrupted.
* Otherwise it will be marked as corrupted later on. */
if (nbytes != p.size) {
if (!p.ParsePacketSize() || nbytes != p.size) {
DEBUG(net, 1, "received a packet with mismatching size from %s", address.GetAddressAsString().c_str());
continue;
}
p.PrepareToRead();
/* Handle the packet */
this->HandleUDPPacket(&p, &address);