From acb85e30faf3aa10d21ab51efa8fe478f13b8361 Mon Sep 17 00:00:00 2001 From: Outfluencer Date: Sat, 21 Sep 2024 01:05:50 +0200 Subject: [PATCH] #3742: Add more checks to InitialHandler --- .../java/net/md_5/bungee/connection/InitialHandler.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java index 091ae9a2..224f231b 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java @@ -196,6 +196,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection @Override public void handle(LegacyHandshake legacyHandshake) throws Exception { + Preconditions.checkState( !this.legacy, "Not expecting LegacyHandshake" ); this.legacy = true; ch.close( bungee.getTranslation( "outdated_client", bungee.getGameVersion() ) ); } @@ -203,6 +204,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection @Override public void handle(LegacyPing ping) throws Exception { + Preconditions.checkState( !this.legacy, "Not expecting LegacyPing" ); this.legacy = true; final boolean v1_5 = ping.isV1_5(); @@ -342,7 +344,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection @Override public void handle(Handshake handshake) throws Exception { - Preconditions.checkState( thisState == State.HANDSHAKE, "Not expecting HANDSHAKE" ); + Preconditions.checkState( thisState == State.HANDSHAKE && !this.legacy, "Not expecting HANDSHAKE" ); this.handshake = handshake; ch.setVersion( handshake.getProtocolVersion() ); ch.getHandle().pipeline().remove( PipelineUtils.LEGACY_KICKER ); @@ -420,7 +422,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection @Override public void handle(LoginRequest loginRequest) throws Exception { - Preconditions.checkState( thisState == State.USERNAME, "Not expecting USERNAME" ); + Preconditions.checkState( thisState == State.USERNAME && this.loginRequest == null, "Not expecting USERNAME" ); if ( !AllowedCharacters.isValidName( loginRequest.getData(), onlineMode ) ) {