From 5503a338faaff7c46d51ef1a2efed170eddcbdc2 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Thu, 23 Jul 2020 19:31:37 +0200 Subject: [PATCH] Check for register/unregister channels with long names --- .../Protocol1_16To1_15_2.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java index 3a16355a1..e2139375b 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java @@ -1,5 +1,6 @@ package us.myles.ViaVersion.protocols.protocol1_16to1_15_2; +import com.google.common.base.Joiner; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -25,6 +26,9 @@ import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.storage.EntityTracker1 import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.util.GsonUtil; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; public class Protocol1_16To1_15_2 extends Protocol { @@ -154,6 +158,27 @@ public class Protocol1_16To1_15_2 extends Protocol checkedChannels = new ArrayList<>(channels.length); + for (String registeredChannel : channels) { + if (registeredChannel.length() > 32) { + if (!Via.getConfig().isSuppressConversionWarnings()) { + Via.getPlatform().getLogger().warning("Ignoring incoming plugin channel register of '" + + registeredChannel + "', as it is longer than 32 characters"); + } + continue; + } + + checkedChannels.add(registeredChannel); + } + + if (checkedChannels.isEmpty()) { + wrapper.cancel(); + return; + } + + wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(checkedChannels).getBytes(StandardCharsets.UTF_8)); } }); }