Prevent infinite loop in StartEncryption (#1150)

This commit is contained in:
ORelio 2021-05-22 11:21:21 +02:00
parent 172e25fef0
commit e6b2b87366

View file

@ -1270,12 +1270,18 @@ namespace MinecraftClient.Protocol.Handlers
socketWrapper.SwitchToEncrypted(secretKey); socketWrapper.SwitchToEncrypted(secretKey);
//Process the next packet //Process the next packet
int packetID = -1; int loopPrevention = UInt16.MaxValue;
Queue<byte> packetData = new Queue<byte>();
while (true) while (true)
{ {
int packetID = -1;
Queue<byte> packetData = new Queue<byte>();
ReadNextPacket(ref packetID, packetData); 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))); handler.OnConnectionLost(ChatBot.DisconnectReason.LoginRejected, ChatParser.ParseText(dataTypes.ReadNextString(packetData)));
return false; return false;