From 514115a85cadcb6983c02fe5acc12ceeddcf7d8b Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 30 Mar 2021 12:10:55 -0400 Subject: [PATCH] Do not use an ASCII string for handshake --- .../proxy/protocol/ProtocolUtils.java | 18 ------------------ .../proxy/protocol/packet/Handshake.java | 2 +- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java index 7da858d9f..ef6eb35ca 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java @@ -97,24 +97,6 @@ public enum ProtocolUtils { } } - /** - * Reads a VarInt length-prefixed ASCII string from the {@code buf}, making sure to not go over - * {@code cap} size. This method is specialized for select parts of the Minecraft protocol where - * ASCII characters are guaranteed to be used. - * - * @param buf the buffer to read from - * @param cap the maximum size of the string, in UTF-8 character length - * @return the decoded string - */ - public static String readAsciiString(ByteBuf buf, int cap) { - int length = readVarInt(buf); - checkFrame(length >= 0, "Got a negative-length string (%s)", length); - checkFrame(length <= cap, "Bad string size (got %s, maximum is %s)", length, cap); - String str = buf.toString(buf.readerIndex(), length, StandardCharsets.US_ASCII); - buf.skipBytes(length); - return str; - } - public static String readString(ByteBuf buf) { return readString(buf, DEFAULT_MAX_STRING_SIZE); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Handshake.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Handshake.java index a1c902057..4ac520ea5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Handshake.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Handshake.java @@ -65,7 +65,7 @@ public class Handshake implements MinecraftPacket { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion ignored) { int realProtocolVersion = ProtocolUtils.readVarInt(buf); this.protocolVersion = ProtocolVersion.getProtocolVersion(realProtocolVersion); - this.serverAddress = ProtocolUtils.readAsciiString(buf, MAXIMUM_HOSTNAME_LENGTH); + this.serverAddress = ProtocolUtils.readString(buf, MAXIMUM_HOSTNAME_LENGTH); this.port = buf.readUnsignedShort(); this.nextStatus = ProtocolUtils.readVarInt(buf); }