summaryrefslogtreecommitdiff
path: root/src/network/core/tcp.cpp
diff options
context:
space:
mode:
authorRubidium <rubidium@openttd.org>2021-04-18 09:01:27 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-04-24 20:42:01 +0200
commitc545cc9d7039a89e23de160b1c93adc959eabda5 (patch)
tree8522a8e09c0b9fa7e3eba8b4becaef15080f5605 /src/network/core/tcp.cpp
parent470d8b66372ceb5a38ce9823d451bddd2f3eca35 (diff)
downloadopenttd-c545cc9d7039a89e23de160b1c93adc959eabda5.tar.xz
Codechange: move more logic about packet size validity and reading into Packet
Diffstat (limited to 'src/network/core/tcp.cpp')
-rw-r--r--src/network/core/tcp.cpp10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp
index a51913d84..1461a9298 100644
--- a/src/network/core/tcp.cpp
+++ b/src/network/core/tcp.cpp
@@ -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;
}