From e6b2b87366e2bc11a2f9215428b047cea8c810c1 Mon Sep 17 00:00:00 2001 From: ORelio Date: Sat, 22 May 2021 11:21:21 +0200 Subject: [PATCH] Prevent infinite loop in StartEncryption (#1150) --- MinecraftClient/Protocol/Handlers/Protocol18.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index e3c0616c..a543a8f1 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -1270,12 +1270,18 @@ namespace MinecraftClient.Protocol.Handlers socketWrapper.SwitchToEncrypted(secretKey); //Process the next packet - int packetID = -1; - Queue packetData = new Queue(); + int loopPrevention = UInt16.MaxValue; while (true) { + int packetID = -1; + Queue packetData = new Queue(); ReadNextPacket(ref packetID, packetData); - if (packetID == 0x00) //Login rejected + if (packetID < 0 || loopPrevention-- < 0) // Failed to read packet or too many iterations (issue #1150) + { + handler.OnConnectionLost(ChatBot.DisconnectReason.ConnectionLost, Translations.Get("error.invalid_encrypt")); + return false; + } + else if (packetID == 0x00) //Login rejected { handler.OnConnectionLost(ChatBot.DisconnectReason.LoginRejected, ChatParser.ParseText(dataTypes.ReadNextString(packetData))); return false;