diff --git a/patches/net/minecraft/network/PacketBuffer.java.patch b/patches/net/minecraft/network/PacketBuffer.java.patch index 893b27c34..66386804e 100644 --- a/patches/net/minecraft/network/PacketBuffer.java.patch +++ b/patches/net/minecraft/network/PacketBuffer.java.patch @@ -55,3 +55,19 @@ return itemstack; } } +@@ -386,6 +390,7 @@ + } + else + { ++ catserver.server.utils.Log4j2_3201_Fixer.matchThrowException(s); // CatServer + return s; + } + } +@@ -393,6 +398,7 @@ + + public PacketBuffer writeString(String string) + { ++ if (catserver.server.utils.Log4j2_3201_Fixer.matchPrintException(string)) string = ""; // CatServer + byte[] abyte = string.getBytes(StandardCharsets.UTF_8); + + if (abyte.length > 32767) diff --git a/src/main/java/catserver/server/utils/Log4j2_3201_Fixer.java b/src/main/java/catserver/server/utils/Log4j2_3201_Fixer.java new file mode 100644 index 000000000..a7d03ed48 --- /dev/null +++ b/src/main/java/catserver/server/utils/Log4j2_3201_Fixer.java @@ -0,0 +1,25 @@ +package catserver.server.utils; + +import java.util.regex.Pattern; + +public class Log4j2_3201_Fixer { + private final static Pattern REGEX = Pattern.compile("\\$\\{jndi:.*}"); + + public static boolean match(String message) { + return REGEX.matcher(message).find(); + } + + public static void matchThrowException(String message) throws RuntimeException { + if (match(message)) { + throw new RuntimeException("Detected log4j2 3201 bug! Message: " + message.replace("$", "\\u0024")); + } + } + + public static boolean matchPrintException(String message) throws RuntimeException { + if (match(message)) { + new RuntimeException("Detected log4j2 3201 bug! Message: " + message.replace("$", "\\u0024")).printStackTrace(); + return true; + } + return false; + } +} diff --git a/src/main/java/net/minecraftforge/server/terminalconsole/MinecraftFormattingConverter.java b/src/main/java/net/minecraftforge/server/terminalconsole/MinecraftFormattingConverter.java index b01efba56..1211f5e45 100644 --- a/src/main/java/net/minecraftforge/server/terminalconsole/MinecraftFormattingConverter.java +++ b/src/main/java/net/minecraftforge/server/terminalconsole/MinecraftFormattingConverter.java @@ -129,6 +129,7 @@ protected MinecraftFormattingConverter(List formatters, boolea @Override public void format(LogEvent event, StringBuilder toAppendTo) { + if (catserver.server.utils.Log4j2_3201_Fixer.matchPrintException(event.getMessage().getFormattedMessage())) return; // CatServer int start = toAppendTo.length(); //noinspection ForLoopReplaceableByForEach for (int i = 0, size = formatters.size(); i < size; i++)