Waterfall/BungeeCord-Patches/0008-Don-t-access-a-ByteBuf-s-underlying-array.patch

91 lines
4.6 KiB
Diff
Raw Normal View History

2018-05-28 23:00:27 +02:00
From fcc7a9df25e9acec9056283d51533eb12f059c85 Mon Sep 17 00:00:00 2001
From: Techcable <Techcable@techcable.net>
Date: Tue, 3 May 2016 20:31:52 -0700
Subject: [PATCH] Don't access a ByteBuf's underlying array
It returns the underlying array storage, and does *not* return a view of the buffer as an array
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java
2018-05-28 23:00:27 +02:00
index d578402b..756f7c2f 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java
2016-08-26 11:05:00 +02:00
@@ -2,6 +2,7 @@ package net.md_5.bungee.protocol.packet;
2016-08-20 22:12:37 +02:00
import com.google.common.base.Preconditions;
2016-08-26 11:05:00 +02:00
import com.google.common.base.Predicate;
2016-08-20 22:12:37 +02:00
+import io.netty.buffer.ByteBufUtil;
2016-08-20 22:34:49 +02:00
import net.md_5.bungee.protocol.DefinedPacket;
import io.netty.buffer.ByteBuf;
import java.io.ByteArrayInputStream;
2016-08-26 11:05:00 +02:00
@@ -29,10 +30,23 @@ public class PluginMessage extends DefinedPacket
2018-05-28 23:00:27 +02:00
return ( input.getTag().equals( "REGISTER" ) || input.getTag().equals( "MC|Brand" ) ) && input.getData().length < Byte.MAX_VALUE;
2016-08-26 11:05:00 +02:00
}
};
- //
+
+ public PluginMessage(String tag, ByteBuf data, boolean allowExtendedPacket) {
+ this(tag, ByteBufUtil.getBytes(data), allowExtendedPacket);
+ }
+
private String tag;
private byte[] data;
+ public void setData(byte[] data) {
+ this.data = Preconditions.checkNotNull(data, "Null data");
+ }
+
+ public void setData(ByteBuf buf) {
+ Preconditions.checkNotNull(buf, "Null buffer");
+ setData(ByteBufUtil.getBytes(buf));
+ }
+
/**
* Allow this packet to be sent as an "extended" packet.
*/
diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
2018-05-28 23:00:27 +02:00
index b34247ce..67a6d247 100644
--- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
+++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
2018-04-02 11:21:24 +02:00
@@ -201,7 +201,7 @@ public class ServerConnector extends PacketHandler
ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer();
DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")", brand );
2016-08-20 22:12:37 +02:00
- user.unsafe().sendPacket( new PluginMessage( "MC|Brand", DefinedPacket.toArray( brand ), handshakeHandler.isServerForge() ) );
+ user.unsafe().sendPacket( new PluginMessage( "MC|Brand", brand, handshakeHandler.isServerForge() ) );
brand.release();
2016-10-30 15:46:05 +01:00
user.setDimension( login.getDimension() );
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
2018-04-02 11:21:24 +02:00
index 931f3f30..9ea61319 100644
--- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
+++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
2018-04-02 11:21:24 +02:00
@@ -241,7 +241,7 @@ public class DownstreamBridge extends PacketHandler
2016-08-20 22:12:37 +02:00
brand = ByteBufAllocator.DEFAULT.heapBuffer();
DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand, brand );
2016-08-20 22:12:37 +02:00
- pluginMessage.setData( DefinedPacket.toArray( brand ) );
+ pluginMessage.setData( brand );
brand.release();
// changes in the packet are ignored so we need to send it manually
con.unsafe().sendPacket( pluginMessage );
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
2017-09-05 19:17:15 +02:00
index 551ae1e1..be9685b9 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
2017-08-18 11:36:42 +02:00
@@ -42,9 +42,9 @@ import net.md_5.bungee.protocol.Varint21LengthFieldPrepender;
public class PipelineUtils
{
- public static final AttributeKey<ListenerInfo> LISTENER = AttributeKey.valueOf( "ListerInfo" );
- public static final AttributeKey<UserConnection> USER = AttributeKey.valueOf( "User" );
- public static final AttributeKey<BungeeServerInfo> TARGET = AttributeKey.valueOf( "Target" );
+ public static final AttributeKey<ListenerInfo> LISTENER = AttributeKey.newInstance("ListerInfo");
+ public static final AttributeKey<UserConnection> USER = AttributeKey.newInstance("User");
+ public static final AttributeKey<BungeeServerInfo> TARGET = AttributeKey.newInstance("Target");
public static final ChannelInitializer<Channel> SERVER_CHILD = new ChannelInitializer<Channel>()
{
@Override
--
2018-05-28 23:00:27 +02:00
2.17.0.windows.1