From 33c12f3bc5998d7af601571aed01a13df99c34f4 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 6 May 2023 11:32:53 -0700 Subject: [PATCH] Fix bounds check (#1071) Fix Chat Crash Update CMakeVariables.txt Add checks for all servers --- dAuthServer/AuthServer.cpp | 2 ++ dChatServer/ChatServer.cpp | 2 ++ dMasterServer/MasterServer.cpp | 2 ++ dWorldServer/WorldServer.cpp | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/dAuthServer/AuthServer.cpp b/dAuthServer/AuthServer.cpp index ddec32db..262886d7 100644 --- a/dAuthServer/AuthServer.cpp +++ b/dAuthServer/AuthServer.cpp @@ -171,6 +171,8 @@ dLogger* SetupLogger() { } void HandlePacket(Packet* packet) { + if (packet->length < 4) return; + if (packet->data[0] == ID_USER_PACKET_ENUM) { if (static_cast(packet->data[1]) == eConnectionType::SERVER) { if (static_cast(packet->data[3]) == eServerMessageType::VERSION_CONFIRM) { diff --git a/dChatServer/ChatServer.cpp b/dChatServer/ChatServer.cpp index 3e3ddfd3..b9fb8556 100644 --- a/dChatServer/ChatServer.cpp +++ b/dChatServer/ChatServer.cpp @@ -203,6 +203,8 @@ void HandlePacket(Packet* packet) { Game::logger->Log("ChatServer", "A server is connecting, awaiting user list."); } + if (packet->length < 4) return; // Nothing left to process. Need 4 bytes to continue. + if (static_cast(packet->data[1]) == eConnectionType::CHAT_INTERNAL) { switch (static_cast(packet->data[3])) { case eChatInternalMessageType::PLAYER_ADDED_NOTIFICATION: diff --git a/dMasterServer/MasterServer.cpp b/dMasterServer/MasterServer.cpp index 4b524d8d..bc0937c2 100644 --- a/dMasterServer/MasterServer.cpp +++ b/dMasterServer/MasterServer.cpp @@ -495,6 +495,8 @@ void HandlePacket(Packet* packet) { } } + if (packet->length < 4) return; + if (static_cast(packet->data[1]) == eConnectionType::MASTER) { switch (static_cast(packet->data[3])) { case eMasterMessageType::REQUEST_PERSISTENT_ID: { diff --git a/dWorldServer/WorldServer.cpp b/dWorldServer/WorldServer.cpp index 4eca86f2..26cbe7ba 100644 --- a/dWorldServer/WorldServer.cpp +++ b/dWorldServer/WorldServer.cpp @@ -728,7 +728,7 @@ void HandlePacket(Packet* packet) { Game::server->SendToMaster(&bitStream); } - if (packet->data[0] != ID_USER_PACKET_ENUM) return; + if (packet->data[0] != ID_USER_PACKET_ENUM || packet->length < 4) return; if (static_cast(packet->data[1]) == eConnectionType::SERVER) { if (static_cast(packet->data[3]) == eServerMessageType::VERSION_CONFIRM) { AuthPackets::HandleHandshake(Game::server, packet);