From f23ec52afd3ba998bb79b13b47cecd28da3c47fe Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Tue, 26 Feb 2019 20:44:07 +0000 Subject: [PATCH] Handle empty minecraft packets Actually detect this and print a message instead of just throwing exceptions down the line, also includes support for the "allow empty packets" for completeness, but, follows the same set of recommendations. --- .../0049-Handle-empty-minecraft-packets.patch | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 BungeeCord-Patches/0049-Handle-empty-minecraft-packets.patch diff --git a/BungeeCord-Patches/0049-Handle-empty-minecraft-packets.patch b/BungeeCord-Patches/0049-Handle-empty-minecraft-packets.patch new file mode 100644 index 0000000..0dfa88f --- /dev/null +++ b/BungeeCord-Patches/0049-Handle-empty-minecraft-packets.patch @@ -0,0 +1,63 @@ +From 17af604ecbbdd56ce2bbf2e342b63083bee4c006 Mon Sep 17 00:00:00 2001 +From: Shane Freeder +Date: Tue, 26 Feb 2019 20:15:54 +0000 +Subject: [PATCH] Handle empty minecraft packets + +Actually detect this and print a message instead of just +throwing exceptions down the line, also includes support +for the "allow empty packets" for completeness, but, +follows the same set of recommendations. + +diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java +index 9e9ea49c..a46bbc78 100644 +--- a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java ++++ b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java +@@ -20,11 +20,18 @@ public class MinecraftDecoder extends MessageToMessageDecoder + private int protocolVersion; + @Setter + private boolean supportsForge = false; ++ private final boolean allowEmptyPackets; // Waterfall + + public MinecraftDecoder(Protocol protocol, boolean server, int protocolVersion) { ++ // Waterfall start ++ this(protocol, server, protocolVersion, false); ++ } ++ public MinecraftDecoder(Protocol protocol, boolean server, int protocolVersion, boolean allowEmptyPackets) { ++ // Waterfall end + this.protocol = protocol; + this.server = server; + this.protocolVersion = protocolVersion; ++ this.allowEmptyPackets = allowEmptyPackets; // Waterfall + } + + @Override +@@ -36,6 +43,13 @@ public class MinecraftDecoder extends MessageToMessageDecoder + Object packetTypeInfo = null; + try + { ++ // Waterfall start ++ if (in.readableBytes() == 0) { ++ if (!allowEmptyPackets) throw new BadPacketException("Empty minecraft packet!"); ++ return; ++ } ++ // Waterfall end ++ + int packetId = DefinedPacket.readVarInt( in ); + packetTypeInfo = packetId; + +diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java +index 8a524a64..e649678e 100644 +--- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java ++++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java +@@ -351,7 +351,7 @@ public final class UserConnection implements ProxiedPlayer + protected void initChannel(Channel ch) throws Exception + { + PipelineUtils.BASE.initChannel( ch ); +- ch.pipeline().addAfter( PipelineUtils.FRAME_DECODER, PipelineUtils.PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, false, getPendingConnection().getVersion() ) ); ++ ch.pipeline().addAfter( PipelineUtils.FRAME_DECODER, PipelineUtils.PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, false, getPendingConnection().getVersion(), bungee.getConfig().isAllowEmptyPackets() ) ); // Waterfall + ch.pipeline().addAfter( PipelineUtils.FRAME_PREPENDER, PipelineUtils.PACKET_ENCODER, new MinecraftEncoder( Protocol.HANDSHAKE, false, getPendingConnection().getVersion() ) ); + ch.pipeline().get( HandlerBoss.class ).setHandler( new ServerConnector( bungee, UserConnection.this, target ) ); + } +-- +2.21.0 +