Skip to content

Commit

Permalink
LOG4J2-3201 PATCH
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Dec 10, 2021
1 parent ab7e22f commit 7450e80
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 20 deletions.
15 changes: 13 additions & 2 deletions patches/net/minecraft/client/main/Main.java.patch
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
--- a/net/minecraft/client/main/Main.java
+++ b/net/minecraft/client/main/Main.java
@@ -1,5 +1,7 @@
@@ -1,5 +1,8 @@
package net.minecraft.client.main;

+import carpet.spark.CarpetSparkAccess;
+import carpet.utils.Log4j2JndiPatch;
+import carpet.worldedit.CarpetWorldEditAccess;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mojang.authlib.properties.PropertyMap;
@@ -70,6 +72,11 @@
@@ -70,6 +73,11 @@
System.out.println("Completely ignored arguments: " + list);
}

Expand All @@ -20,3 +21,13 @@
String s = func_206236_a(optionset, optionspec5);
Proxy proxy = Proxy.NO_PROXY;

@@ -162,6 +170,9 @@

static
{
+ // TISCM LOG4J2-3201 PATCH
+ Log4j2JndiPatch.patch();
+
System.setProperty("java.awt.headless", "true");
}
}
50 changes: 32 additions & 18 deletions patches/net/minecraft/server/MinecraftServer.java.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1,5 +1,19 @@
@@ -1,5 +1,20 @@
package net.minecraft.server;

+import carpet.CarpetServer;
Expand All @@ -14,21 +14,22 @@
+import carpet.settings.CarpetSettings;
+import carpet.spark.CarpetSparkAccess;
+import carpet.utils.CarpetProfiler;
+import carpet.utils.Log4j2JndiPatch;
+import carpet.utils.Messenger;
+import carpet.utils.TISCMConfig;
+import carpet.worldedit.CarpetWorldEditAccess;
import com.google.common.base.Stopwatch;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@@ -178,6 +192,7 @@
@@ -178,6 +193,7 @@
public final Queue < FutureTask<? >> futureTaskQueue = Queues.newConcurrentLinkedQueue();
private Thread serverThread;
private long serverTime = Util.milliTime();
+ public long actualServerTime = Util.milliTime();
@OnlyIn(Dist.CLIENT)
private boolean worldIconSet;
private final IReloadableResourceManager resourceManager = new SimpleReloadableResourceManager(ResourcePackType.SERVER_DATA);
@@ -212,6 +227,8 @@
@@ -212,6 +228,8 @@
this.resourceManager.addReloadListener(this.lootTableManager);
this.resourceManager.addReloadListener(this.functionManager);
this.resourceManager.addReloadListener(this.advancementManager);
Expand All @@ -37,7 +38,7 @@
}

public abstract boolean init() throws IOException;
@@ -571,7 +588,13 @@
@@ -571,7 +589,13 @@
public void stopServer()
{
LOGGER.info("Stopping server");
Expand All @@ -51,7 +52,7 @@
if (this.getNetworkSystem() != null)
{
this.getNetworkSystem().terminateEndpoints();
@@ -639,34 +662,64 @@
@@ -639,34 +663,64 @@
{
try
{
Expand Down Expand Up @@ -133,7 +134,7 @@
}
}
else
@@ -782,7 +835,16 @@
@@ -782,7 +836,16 @@
{
long i = Util.nanoTime();
++this.tickCounter;
Expand All @@ -150,7 +151,7 @@
if (this.startProfiling)
{
this.startProfiling = false;
@@ -790,6 +852,9 @@
@@ -790,6 +853,9 @@
}

this.profiler.startSection("root");
Expand All @@ -160,7 +161,7 @@
this.updateTimeLightAndEntities(hasTimeLeft);

if (i - this.nanoTimeSinceStatusRefresh >= 5000000000L)
@@ -810,10 +875,26 @@
@@ -810,10 +876,26 @@

if (this.tickCounter % 900 == 0)
{
Expand All @@ -187,7 +188,7 @@
}

this.profiler.startSection("snooper");
@@ -829,16 +910,30 @@
@@ -829,16 +911,30 @@
}

this.profiler.endSection();
Expand Down Expand Up @@ -218,23 +219,23 @@
FutureTask<?> futuretask;

while ((futuretask = this.futureTaskQueue.poll()) != null)
@@ -847,6 +942,7 @@
@@ -847,6 +943,7 @@
}

this.profiler.endStartSection("commandFunctions");
+ MicroTimingLoggerManager.setTickStage(TickStage.COMMAND_FUNCTION); // TISCM Micro Timing logger
this.getFunctionManager().tick();
this.profiler.endStartSection("levels");

@@ -870,6 +966,7 @@
@@ -870,6 +967,7 @@

this.profiler.startSection("tick");

+ // Update suppression fix
try
{
worldserver.tick(hasTimeLeft);
@@ -878,9 +975,15 @@
@@ -878,9 +976,15 @@
{
CrashReport crashreport = CrashReport.makeCrashReport(throwable1, "Exception ticking world");
worldserver.fillCrashReport(crashreport);
Expand All @@ -251,7 +252,7 @@
try
{
worldserver.tickEntities();
@@ -889,7 +992,12 @@
@@ -889,7 +993,12 @@
{
CrashReport crashreport1 = CrashReport.makeCrashReport(throwable, "Exception ticking world entities");
worldserver.fillCrashReport(crashreport1);
Expand All @@ -265,7 +266,7 @@
}

this.profiler.endSection();
@@ -905,10 +1013,13 @@
@@ -905,10 +1014,13 @@
}))[this.tickCounter % 100] = Util.nanoTime() - i;
}

Expand All @@ -279,7 +280,20 @@
this.profiler.endStartSection("tickables");

for (int j = 0; j < this.tickables.size(); ++j)
@@ -1004,6 +1115,11 @@
@@ -929,6 +1041,12 @@
this.tickables.add(tickable);
}

+ static
+ {
+ // TISCM LOG4J2-3201 PATCH
+ Log4j2JndiPatch.patch();
+ }
+
public static void main(String[] p_main_0_)
{
Bootstrap.register();
@@ -1004,6 +1122,11 @@
}
}

Expand All @@ -291,7 +305,7 @@
YggdrasilAuthenticationService yggdrasilauthenticationservice = new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString());
MinecraftSessionService minecraftsessionservice = yggdrasilauthenticationservice.createMinecraftSessionService();
GameProfileRepository gameprofilerepository = yggdrasilauthenticationservice.createProfileRepository();
@@ -1142,7 +1258,8 @@
@@ -1142,7 +1265,8 @@

public String getServerModName()
{
Expand All @@ -301,7 +315,7 @@
}

public CrashReport addServerInfoToCrashReport(CrashReport report)
@@ -1605,6 +1722,12 @@
@@ -1605,6 +1729,12 @@
{
return this.serverTime;
}
Expand All @@ -314,7 +328,7 @@

public Thread getServerThread()
{
@@ -1825,4 +1948,17 @@
@@ -1825,4 +1955,17 @@
return 0;
}
}
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/carpet/utils/Log4j2JndiPatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package carpet.utils;

import org.apache.logging.log4j.core.LoggerContext;

/**
* Fix from 1.18.1-rc3
*/
public class Log4j2JndiPatch
{
private static final LoggerContext loggerContext = LoggerContext.getContext(false);

public static void patch()
{
// doesn't work before log4j2 2.10
// System.setProperty("log4j2.formatMsgNoLookups", "true");

loggerContext.addPropertyChangeListener(event -> applyFix());
applyFix();
}

private static void applyFix()
{
try
{
loggerContext.getConfiguration().getStrSubstitutor().setVariableResolver(null);
}
catch (Throwable throwable)
{
throwable.printStackTrace();
throw new RuntimeException("JNDI patch failed");
}
}
}

0 comments on commit 7450e80

Please sign in to comment.