Fix stacktrace deobf where thrownProxy got initialized before rewriting (#6684)

This commit is contained in:
Jason 2021-09-30 13:05:51 -05:00 committed by GitHub
parent 2b404b0cfa
commit 8ee9bdd6ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 22 deletions

View File

@ -6,7 +6,7 @@ Subject: [PATCH] Deobfuscate stacktraces in log messages, crash reports, and
diff --git a/build.gradle.kts b/build.gradle.kts diff --git a/build.gradle.kts b/build.gradle.kts
index eea412347cef390555166a988058ae877afdfa4a..b35e54380cb23758a813fa24d13b888f36906c23 100644 index fd037da8b655b329ef016356519a69ca2621fd4f..03c9f894a2eaa065c456843eef4d3ab1a25565c3 100644
--- a/build.gradle.kts --- a/build.gradle.kts
+++ b/build.gradle.kts +++ b/build.gradle.kts
@@ -1,8 +1,12 @@ @@ -1,8 +1,12 @@
@ -120,10 +120,10 @@ index 0bb4aaa546939b67a5d22865190f30478a9337c1..d3e619655382e50e9ac9323ed942502d
diff --git a/src/main/java/io/papermc/paper/logging/StacktraceDeobfuscatingRewritePolicy.java b/src/main/java/io/papermc/paper/logging/StacktraceDeobfuscatingRewritePolicy.java diff --git a/src/main/java/io/papermc/paper/logging/StacktraceDeobfuscatingRewritePolicy.java b/src/main/java/io/papermc/paper/logging/StacktraceDeobfuscatingRewritePolicy.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..d019802a36dbaca4bf299a55d28381e43d6b976f index 0000000000000000000000000000000000000000..c701ef3c287f62aa0ebfbdbd6da6ed82a1c7793c
--- /dev/null --- /dev/null
+++ b/src/main/java/io/papermc/paper/logging/StacktraceDeobfuscatingRewritePolicy.java +++ b/src/main/java/io/papermc/paper/logging/StacktraceDeobfuscatingRewritePolicy.java
@@ -0,0 +1,31 @@ @@ -0,0 +1,38 @@
+package io.papermc.paper.logging; +package io.papermc.paper.logging;
+ +
+import io.papermc.paper.util.StacktraceDeobfuscator; +import io.papermc.paper.util.StacktraceDeobfuscator;
@ -132,7 +132,8 @@ index 0000000000000000000000000000000000000000..d019802a36dbaca4bf299a55d28381e4
+import org.apache.logging.log4j.core.appender.rewrite.RewritePolicy; +import org.apache.logging.log4j.core.appender.rewrite.RewritePolicy;
+import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory; +import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.jetbrains.annotations.NotNull; +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.checkerframework.checker.nullness.qual.NonNull;
+ +
+@Plugin( +@Plugin(
+ name = "StacktraceDeobfuscatingRewritePolicy", + name = "StacktraceDeobfuscatingRewritePolicy",
@ -141,17 +142,23 @@ index 0000000000000000000000000000000000000000..d019802a36dbaca4bf299a55d28381e4
+ printObject = true + printObject = true
+) +)
+public final class StacktraceDeobfuscatingRewritePolicy implements RewritePolicy { +public final class StacktraceDeobfuscatingRewritePolicy implements RewritePolicy {
+ private StacktraceDeobfuscatingRewritePolicy() {
+ }
+
+ @Override + @Override
+ public @NotNull LogEvent rewrite(final @NotNull LogEvent rewrite) { + public @NonNull LogEvent rewrite(final @NonNull LogEvent rewrite) {
+ final Throwable thrown = rewrite.getThrown(); + final Throwable thrown = rewrite.getThrown();
+ if (thrown != null) { + if (thrown != null) {
+ StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(thrown); + StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(thrown);
+ return new Log4jLogEvent.Builder(rewrite)
+ .setThrownProxy(null)
+ .build();
+ } + }
+ return rewrite; + return rewrite;
+ } + }
+ +
+ @PluginFactory + @PluginFactory
+ public static @NotNull StacktraceDeobfuscatingRewritePolicy createPolicy() { + public static @NonNull StacktraceDeobfuscatingRewritePolicy createPolicy() {
+ return new StacktraceDeobfuscatingRewritePolicy(); + return new StacktraceDeobfuscatingRewritePolicy();
+ } + }
+} +}

View File

@ -230,26 +230,17 @@ index 0000000000000000000000000000000000000000..34734bb969a1a74c7a4f9c17d40ebf00
+ } + }
+} +}
diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml
index 2e421eaac80cf251b32e0bb504dd54a73edf4986..5704146ae84747cafd4b5f504ba071f6be99f425 100644 index 2e421eaac80cf251b32e0bb504dd54a73edf4986..74ccc67e3c12dc5182602fb691ef3ddeb5b53280 100644
--- a/src/main/resources/log4j2.xml --- a/src/main/resources/log4j2.xml
+++ b/src/main/resources/log4j2.xml +++ b/src/main/resources/log4j2.xml
@@ -30,7 +30,7 @@ @@ -34,6 +34,10 @@
<DefaultRolloverStrategy max="1000"/>
</RollingRandomAccessFile>
<Async name="Async">
- <AppenderRef ref="rewrite"/>
+ <AppenderRef ref="rewrite2"/>
</Async> </Async>
<Rewrite name="rewrite"> <Rewrite name="rewrite">
<StacktraceDeobfuscatingRewritePolicy /> <StacktraceDeobfuscatingRewritePolicy />
@@ -38,6 +38,10 @@ + <AppenderRef ref="rewrite2"/>
<AppenderRef ref="TerminalConsole" level="info"/> + </Rewrite>
<AppenderRef ref="ServerGuiConsole" level="info"/>
</Rewrite>
+ <Rewrite name="rewrite2"> + <Rewrite name="rewrite2">
+ <ExtraClassInfoRewritePolicy /> + <ExtraClassInfoRewritePolicy />
+ <AppenderRef ref="rewrite"/> <AppenderRef ref="File"/>
+ </Rewrite> <AppenderRef ref="TerminalConsole" level="info"/>
</Appenders> <AppenderRef ref="ServerGuiConsole" level="info"/>
<Loggers>
<Root level="info">