Allows user to enable message lookup

This commit is contained in:
Glavo 2021-12-18 11:00:45 +08:00 committed by Yuhui Huang
parent 651fa6e2d1
commit 99b55d03c1
2 changed files with 19 additions and 20 deletions

View File

@ -180,15 +180,15 @@ public class DefaultLauncher extends Launcher {
res.addDefault("-Dfml.ignoreInvalidMinecraftCertificates=", "true");
res.addDefault("-Dfml.ignorePatchDiscrepancies=", "true");
// Fix RCE vulnerability of log4j2
res.addDefault("-Dlog4j2.formatMsgNoLookups=", "true");
res.addDefault("-Djava.rmi.server.useCodebaseOnly=", "true");
res.addDefault("-Dcom.sun.jndi.rmi.object.trustURLCodebase=", "false");
res.addDefault("-Dcom.sun.jndi.cosnaming.object.trustURLCodebase=", "false");
}
if (isUsingLog4j()) {
// Fix RCE vulnerability of log4j2
res.addDefault("-Djava.rmi.server.useCodebaseOnly=", "true");
res.addDefault("-Dcom.sun.jndi.rmi.object.trustURLCodebase=", "false");
res.addDefault("-Dcom.sun.jndi.cosnaming.object.trustURLCodebase=", "false");
String formatMsgNoLookups = res.addDefault("-Dlog4j2.formatMsgNoLookups=", "true");
if (!"-Dlog4j2.formatMsgNoLookups=false".equals(formatMsgNoLookups) && isUsingLog4j()) {
res.addDefault("-Dlog4j.configurationFile=", getLog4jConfigurationFile().getAbsolutePath());
}
@ -476,7 +476,6 @@ public class DefaultLauncher extends Launcher {
private Map<String, String> getEnvVars() {
String versionName = Optional.ofNullable(options.getVersionName()).orElse(version.getId());
Map<String, String> env = new HashMap<>();
env.put("LOG4J_FORMAT_MSG_NO_LOOKUPS", "true");
env.put("INST_NAME", versionName);
env.put("INST_ID", versionName);
env.put("INST_DIR", repository.getVersionRoot(version.getId()).getAbsolutePath());

View File

@ -83,33 +83,33 @@ public final class CommandBuilder {
return this;
}
public CommandBuilder addDefault(String opt) {
public String addDefault(String opt) {
for (Item item : raw) {
if (item.arg.equals(opt)) {
return this;
return item.arg;
}
}
raw.add(new Item(opt, true));
return this;
return null;
}
public CommandBuilder addDefault(String opt, String value) {
public String addDefault(String opt, String value) {
for (Item item : raw) {
if (item.arg.startsWith(opt)) {
LOG.info("Default option '" + opt + value + "' is suppressed by '" + item.arg + "'");
return this;
return item.arg;
}
}
raw.add(new Item(opt + value, true));
return this;
return null;
}
public CommandBuilder addUnstableDefault(String opt, boolean value) {
public String addUnstableDefault(String opt, boolean value) {
for (Item item : raw) {
final Matcher matcher = UNSTABLE_BOOLEAN_OPTION_PATTERN.matcher(item.arg);
if (matcher.matches()) {
if (matcher.group("key").equals(opt)) {
return this;
return item.arg;
}
}
}
@ -119,21 +119,21 @@ public final class CommandBuilder {
} else {
raw.add(new Item("-XX:-" + opt, true));
}
return this;
return null;
}
public CommandBuilder addUnstableDefault(String opt, String value) {
public String addUnstableDefault(String opt, String value) {
for (Item item : raw) {
final Matcher matcher = UNSTABLE_OPTION_PATTERN.matcher(item.arg);
if (matcher.matches()) {
if (matcher.group("key").equals(opt)) {
return this;
return item.arg;
}
}
}
raw.add(new Item("-XX:" + opt + "=" + value, true));
return this;
return null;
}
public boolean removeIf(Predicate<String> pred) {