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.
This commit is contained in:
Shane Freeder 2019-02-26 20:44:07 +00:00
parent f2cd0938da
commit f23ec52afd

View File

@ -0,0 +1,63 @@
From 17af604ecbbdd56ce2bbf2e342b63083bee4c006 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
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<ByteBuf>
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<ByteBuf>
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