Ignore empty packets

Make ignoring empty packets the default behavior vs hiding it
behind a configuration option, allowing such packets is less harmful
than the current handling of them
This commit is contained in:
Shane Freeder 2019-09-24 05:46:15 +01:00
parent 420f7836b3
commit 2b3b0ec998
No known key found for this signature in database
GPG Key ID: A3F61EA5A085289C
11 changed files with 77 additions and 209 deletions

View File

@ -1,111 +0,0 @@
From 59cd643646283aa72acf873abea280d7c59ceeba Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Fri, 12 Oct 2018 14:28:52 +0100
Subject: [PATCH] Add Configuration to allow empty packets
This setting provides the ability to allow servers/clients
to send empty packets without kicking the player with an error.
This option is not encouraged or supported in any capacity, and is
provided as a last ditch effort for server owners to allow players
to connect in such a broken state as allowed by vanilla.
diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
index 058cca67..46adc983 100644
--- a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
+++ b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
@@ -207,4 +207,11 @@ public interface ProxyConfig
* @return should we disable the tab completion limit for 1.13+ clients
*/
boolean isDisableModernTabLimiter();
+
+ /**
+ * Should we allow empty packets
+ *
+ * @return should we allow empty packets
+ */
+ boolean isAllowEmptyPackets();
}
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
index e903fd09..98a54601 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
@@ -11,6 +11,13 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
{
private static boolean DIRECT_WARNING;
+ // Waterfall start
+ private boolean allowEmptyPackets;
+
+ public Varint21FrameDecoder(boolean allowEmptyPackets) {
+ this.allowEmptyPackets = allowEmptyPackets;
+ }
+ // Waterfall end
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
@@ -30,7 +37,7 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
if ( buf[i] >= 0 )
{
int length = DefinedPacket.readVarInt( Unpooled.wrappedBuffer( buf ) );
- if ( length == 0 )
+ if ( length == 0 && !allowEmptyPackets) // Waterfall
{
throw new CorruptedFrameException( "Empty Packet!" );
}
diff --git a/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java b/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
index 4ff8da6d..f28f0111 100644
--- a/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
+++ b/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
@@ -42,6 +42,17 @@ public class WaterfallConfiguration extends Configuration {
private int tabThrottle = 1000;
private boolean disableModernTabLimiter = true;
+
+ /**
+ * This setting provides the ability to allow servers/clients
+ * to send empty packets without kicking the player with an error.
+ *
+ * This option is not encouraged or supported in any capacity, and is
+ * provided as a last ditch effort for server owners to allow players
+ * to connect in such a broken state as allowed by vanilla.
+ */
+ private boolean allowEmptyPackets = false;
+
@Override
public void load() {
super.load();
@@ -53,6 +64,7 @@ public class WaterfallConfiguration extends Configuration {
// Throttling options
tabThrottle = config.getInt("throttling.tab_complete", tabThrottle);
disableModernTabLimiter = config.getBoolean("disable_modern_tab_limiter", disableModernTabLimiter);
+ allowEmptyPackets = config.getBoolean("allow_empty_packets", allowEmptyPackets);
}
@Override
@@ -79,4 +91,9 @@ public class WaterfallConfiguration extends Configuration {
public boolean isDisableModernTabLimiter() {
return disableModernTabLimiter;
}
+
+ @Override
+ public boolean isAllowEmptyPackets() {
+ return allowEmptyPackets;
+ }
}
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
index 23241d68..051430ce 100644
--- a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
+++ b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
@@ -146,7 +146,7 @@ public class PipelineUtils
ch.config().setWriteBufferWaterMark( MARK );
ch.pipeline().addLast( TIMEOUT_HANDLER, new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) );
- ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder() );
+ ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder( BungeeCord.getInstance().getConfig().isAllowEmptyPackets()) ); // Waterfall
ch.pipeline().addLast( FRAME_PREPENDER, framePrepender );
ch.pipeline().addLast( BOSS_HANDLER, new HandlerBoss() );
--
2.21.0

View File

@ -0,0 +1,42 @@
From dc105ad9e7123923267007948e8323c5623ed7df Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Fri, 12 Oct 2018 14:28:52 +0100
Subject: [PATCH] Ignore empty packets
This patch puts the proxy more inline with the client in that empty
packets will be ignored. While empty packets are a sign of bad plugins,
they are effectivly harmless vs the cost of the exception in general
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..71ddf022 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
@@ -36,6 +36,12 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
Object packetTypeInfo = null;
try
{
+ // Waterfall start
+ if (in.readableBytes() == 0) {
+ return;
+ }
+ // Waterfall end
+
int packetId = DefinedPacket.readVarInt( in );
packetTypeInfo = packetId;
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
index e903fd09..25ee2027 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
@@ -30,7 +30,7 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
if ( buf[i] >= 0 )
{
int length = DefinedPacket.readVarInt( Unpooled.wrappedBuffer( buf ) );
- if ( length == 0 )
+ if ( false && length == 0) // Waterfall - ignore
{
throw new CorruptedFrameException( "Empty Packet!" );
}
--
2.23.0

View File

@ -1,14 +1,14 @@
From 5c4d4e11b2329b221394f7b216c749edc00c57bf Mon Sep 17 00:00:00 2001
From c47d272e783d604efcca9ebd9dadc69f2eccf750 Mon Sep 17 00:00:00 2001
From: creeper123123321 <creeper123123321@gmail.com>
Date: Thu, 17 Jan 2019 03:25:59 +0000
Subject: [PATCH] Don't use a bytebuf for packet decoding
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
index 98a54601..8de4d9be 100644
index 25ee2027..743d65e4 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
@@ -24,8 +24,7 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
@@ -17,8 +17,7 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
{
in.markReaderIndex();
@ -18,7 +18,7 @@ index 98a54601..8de4d9be 100644
{
if ( !in.isReadable() )
{
@@ -33,10 +32,13 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
@@ -26,10 +25,13 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
return;
}
@ -32,10 +32,10 @@ index 98a54601..8de4d9be 100644
+ in.resetReaderIndex();
+ int length = DefinedPacket.readVarInt( in );
+ // Waterfall end
if ( length == 0 && !allowEmptyPackets) // Waterfall
if ( false && length == 0) // Waterfall - ignore
{
throw new CorruptedFrameException( "Empty Packet!" );
@@ -46,26 +48,11 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
@@ -39,26 +41,11 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
{
in.resetReaderIndex();
return;
@ -67,5 +67,5 @@ index 98a54601..8de4d9be 100644
}
}
--
2.21.0
2.23.0

View File

@ -1,4 +1,4 @@
From 66bf7487b7d6ac842ccb685b8e24d00cc63f6367 Mon Sep 17 00:00:00 2001
From 24451de40fd98201fd6cd75b113d0e10d8bfa0d6 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Mon, 14 Jan 2019 03:35:21 +0000
Subject: [PATCH] Provide an option to disable entity metadata rewriting
@ -12,13 +12,13 @@ may also create various issues with mods which do not support this,
hence why the configuration option is provided
diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
index 46adc983..0e69db36 100644
index 058cca67..6bc54495 100644
--- a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
+++ b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
@@ -214,4 +214,9 @@ public interface ProxyConfig
* @return should we allow empty packets
@@ -207,4 +207,9 @@ public interface ProxyConfig
* @return should we disable the tab completion limit for 1.13+ clients
*/
boolean isAllowEmptyPackets();
boolean isDisableModernTabLimiter();
+
+ /**
+ * @return Should we disable entity metadata rewriting?
@ -26,29 +26,29 @@ index 46adc983..0e69db36 100644
+ boolean isDisableEntityMetadataRewrite();
}
diff --git a/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java b/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
index f28f0111..41a71f65 100644
index 4ff8da6d..e860214f 100644
--- a/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
+++ b/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
@@ -53,6 +53,8 @@ public class WaterfallConfiguration extends Configuration {
*/
private boolean allowEmptyPackets = false;
@@ -42,6 +42,8 @@ public class WaterfallConfiguration extends Configuration {
private int tabThrottle = 1000;
private boolean disableModernTabLimiter = true;
+ private boolean disableEntityMetadataRewrite = false;
+
@Override
public void load() {
super.load();
@@ -65,6 +67,7 @@ public class WaterfallConfiguration extends Configuration {
@@ -53,6 +55,7 @@ public class WaterfallConfiguration extends Configuration {
// Throttling options
tabThrottle = config.getInt("throttling.tab_complete", tabThrottle);
disableModernTabLimiter = config.getBoolean("disable_modern_tab_limiter", disableModernTabLimiter);
allowEmptyPackets = config.getBoolean("allow_empty_packets", allowEmptyPackets);
+ disableEntityMetadataRewrite = config.getBoolean("disable_entity_metadata_rewrite", disableEntityMetadataRewrite);
}
@Override
@@ -96,4 +99,9 @@ public class WaterfallConfiguration extends Configuration {
public boolean isAllowEmptyPackets() {
return allowEmptyPackets;
@@ -79,4 +82,9 @@ public class WaterfallConfiguration extends Configuration {
public boolean isDisableModernTabLimiter() {
return disableModernTabLimiter;
}
+
+ @Override
@ -233,5 +233,5 @@ index 00000000..cb81d1dd
+// Waterfall end
\ No newline at end of file
--
2.21.0 (Apple Git-120)
2.23.0

View File

@ -1,4 +1,4 @@
From 64d9097f51560007e15d0c3ef63a024e7562e4b1 Mon Sep 17 00:00:00 2001
From 94ced6ab8ca487304c30dfbed044e9510c436590 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Thu, 14 Mar 2019 07:44:06 +0000
Subject: [PATCH] Add ProxyDefineCommandsEvent
@ -105,5 +105,5 @@ index fba84905..1f8a2439 100644
LiteralCommandNode dummy = LiteralArgumentBuilder.literal( command.getKey() )
.then( RequiredArgumentBuilder.argument( "args", StringArgumentType.greedyString() )
--
2.21.0
2.23.0

View File

@ -1,63 +0,0 @@
From 7960a4c2a4959570f74e1c931b1d0332a4cd8259 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

View File

@ -1,4 +1,4 @@
From 9de373cbf48bf9e971def774c5611cf8dc91f891 Mon Sep 17 00:00:00 2001
From 1cd07eb6820d14d1a1970d7c8c056d6ee1d39767 Mon Sep 17 00:00:00 2001
From: kashike <kashike@vq.lc>
Date: Wed, 20 Mar 2019 21:39:12 -0700
Subject: [PATCH] Use proper max length for serverbound chat packet
@ -72,5 +72,5 @@ index ffcd815c..0ded6739 100644
if ( direction == ProtocolConstants.Direction.TO_CLIENT )
{
--
2.21.0
2.23.0

View File

@ -1,4 +1,4 @@
From 2f6ad505879900bc8504ae63336e67f17b8cac8a Mon Sep 17 00:00:00 2001
From 38b999c122f1614d6dd763ef20f9feda9bcfddc0 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Tue, 26 Mar 2019 04:28:18 +0000
Subject: [PATCH] Report slow events in milliseconds
@ -27,5 +27,5 @@ index 81bd18f0..9408e6c2 100644
}
return event;
--
2.21.0
2.23.0

View File

@ -1,11 +1,11 @@
From f8145502b28ce0b36f31ea74efe4ab1c743d8275 Mon Sep 17 00:00:00 2001
From 90298e0454419d72aa080e3c68cb268eac64a6b4 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Sat, 30 Mar 2019 15:11:11 +0000
Subject: [PATCH] Fix upstream javadocs
diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
index 0e69db36..cbcf8a24 100644
index 6bc54495..fd422f36 100644
--- a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
+++ b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
@@ -16,22 +16,27 @@ public interface ProxyConfig
@ -147,5 +147,5 @@ index 5d2b088c..be32ba89 100644
* @return the underlying executor service or compatible wrapper
*/
--
2.21.0
2.23.0

View File

@ -1,4 +1,4 @@
From 8bc11ea14a2b4cc3c104a9b455066a4fc8977996 Mon Sep 17 00:00:00 2001
From 9005b5db9f69d902e62b645acc47e9fd3d2fb2fd Mon Sep 17 00:00:00 2001
From: Colin Godsey <crgodsey@gmail.com>
Date: Tue, 16 Apr 2019 07:25:52 -0600
Subject: [PATCH] OSX native zlib and crypto
@ -329,5 +329,5 @@ literal 0
HcmV?d00001
--
2.21.0
2.23.0

View File

@ -1,4 +1,4 @@
From 39f9f9796d555c8c373444a9afa988bb9b647e81 Mon Sep 17 00:00:00 2001
From 37fe29e359d3de76e83f85b9311a5ce01a79c1c7 Mon Sep 17 00:00:00 2001
From: Mark Vainomaa <mikroskeem@mikroskeem.eu>
Date: Wed, 17 Apr 2019 09:24:38 +0300
Subject: [PATCH] Speed up packet construction
@ -343,5 +343,5 @@ index 87093807..c2b0e12c 100644
final int getId(Class<? extends DefinedPacket> packet, int version)
{
--
2.22.0
2.23.0