From b18671f11337b6c0d9252d29223dbb2bcb8544f3 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Sat, 27 Aug 2022 01:47:52 -0700 Subject: [PATCH] Move packet type check to after packet data recv --- source/server/SocketClient.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 8abc7e6..407ac98 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -133,8 +133,7 @@ bool SocketClient::RECV() { int fullSize = header->mPacketSize + sizeof(Packet); - if (header->mType > PacketType::UNKNOWN && header->mType < PacketType::End && - fullSize <= MAXPACKSIZE && fullSize > 0 && valread == sizeof(Packet)) { + if (fullSize <= MAXPACKSIZE && fullSize > 0 && valread == sizeof(Packet)) { if (header->mType != PLAYERINF && header->mType != HACKCAPINF) { Logger::log("Received packet (from %02X%02X):", header->mUserID.data[0], @@ -171,6 +170,12 @@ bool SocketClient::RECV() { } } + if (!(header->mType > PacketType::UNKNOWN && header->mType < PacketType::End)) { + Logger::log("Failed to acquire valid packet type! Packet Type: %d Full Packet Size %d valread size: %d", header->mType, fullSize, valread); + free(packetBuf); + return true; + } + Packet *packet = reinterpret_cast(packetBuf); if(mPacketQueue.size() < maxBufSize - 1) { @@ -180,7 +185,7 @@ bool SocketClient::RECV() { } } } else { - Logger::log("Failed to aquire valid data! Packet Type: %d Full Packet Size %d valread size: %d", header->mType, fullSize, valread); + Logger::log("Failed to acquire valid data! Packet Type: %d Full Packet Size %d valread size: %d", header->mType, fullSize, valread); } return true;