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

@@ -155,8 +155,8 @@ Packet *NetworkTCPSocketHandler::ReceivePacket()
Packet *p = this->packet_recv;
/* Read packet size */
if (p->pos < sizeof(PacketSize)) {
while (p->pos < sizeof(PacketSize)) {
if (!p->HasPacketSizeData()) {
while (!p->HasPacketSizeData()) {
/* Read the size of the packet */
res = recv(this->sock, (char*)p->buffer + p->pos, sizeof(PacketSize) - p->pos, 0);
if (res == -1) {
@@ -178,10 +178,8 @@ Packet *NetworkTCPSocketHandler::ReceivePacket()
p->pos += res;
}
/* Read the packet size from the received packet */
p->ReadRawPacketSize();
if (p->size > SEND_MTU) {
/* Parse the size in the received packet and if not valid, close the connection. */
if (!p->ParsePacketSize()) {
this->CloseConnection();
return nullptr;
}