CodeStyle для EnvHelper

This commit is contained in:
Gravit 2018-10-26 21:42:20 +07:00
parent 91f9e11b36
commit 23f67c2160
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 17 additions and 13 deletions

View file

@ -19,7 +19,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep
LogHelper.printVersion("Launcher"); LogHelper.printVersion("Launcher");
JVMHelper.checkStackTrace(ClientLauncherWrapper.class); JVMHelper.checkStackTrace(ClientLauncherWrapper.class);
JVMHelper.verifySystemProperties(Launcher.class, true); JVMHelper.verifySystemProperties(Launcher.class, true);
EnvHelper.checkDangerousParametrs(); EnvHelper.checkDangerousParams();
LogHelper.debug("Restart Launcher"); LogHelper.debug("Restart Launcher");
ProcessBuilder processBuilder = new ProcessBuilder(); ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.inheritIO(); processBuilder.inheritIO();

View file

@ -42,7 +42,6 @@
import ru.gravit.launcher.request.auth.AuthRequest; import ru.gravit.launcher.request.auth.AuthRequest;
import ru.gravit.launcher.request.auth.CheckServerRequest; import ru.gravit.launcher.request.auth.CheckServerRequest;
import ru.gravit.launcher.request.auth.JoinServerRequest; import ru.gravit.launcher.request.auth.JoinServerRequest;
import ru.gravit.launcher.request.update.LegacyLauncherRequest;
import ru.gravit.launcher.request.update.UpdateRequest; import ru.gravit.launcher.request.update.UpdateRequest;
import ru.gravit.launcher.request.uuid.BatchProfileByUsernameRequest; import ru.gravit.launcher.request.uuid.BatchProfileByUsernameRequest;
import ru.gravit.launcher.request.uuid.ProfileByUUIDRequest; import ru.gravit.launcher.request.uuid.ProfileByUUIDRequest;
@ -151,7 +150,7 @@ public static void addLauncherClassBindings(Map<String, Object> bindings) {
public static void main(String... args) throws Throwable { public static void main(String... args) throws Throwable {
JVMHelper.checkStackTrace(LauncherEngine.class); JVMHelper.checkStackTrace(LauncherEngine.class);
JVMHelper.verifySystemProperties(Launcher.class, true); JVMHelper.verifySystemProperties(Launcher.class, true);
EnvHelper.checkDangerousParametrs(); EnvHelper.checkDangerousParams();
if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set"); if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set");
LogHelper.printVersion("Launcher"); LogHelper.printVersion("Launcher");
// Start Launcher // Start Launcher

View file

@ -407,7 +407,7 @@ public static void main(String... args) throws Throwable {
} }
checkJVMBitsAndVersion(); checkJVMBitsAndVersion();
JVMHelper.verifySystemProperties(ClientLauncher.class, true); JVMHelper.verifySystemProperties(ClientLauncher.class, true);
EnvHelper.checkDangerousParametrs(); EnvHelper.checkDangerousParams();
JVMHelper.checkStackTrace(ClientLauncher.class); JVMHelper.checkStackTrace(ClientLauncher.class);
LogHelper.printVersion("Client Launcher"); LogHelper.printVersion("Client Launcher");
// Read and delete params file // Read and delete params file

View file

@ -14,20 +14,25 @@ public class EnvHelper {
} }
public static void addEnv(ProcessBuilder builder) { public static void addEnv(ProcessBuilder builder) {
Map<String, String> repl = builder.environment(); Map<String, String> map = builder.environment();
for (String str : toTest) { for (String env : toTest) {
repl.put(str, ""); if(map.containsKey(env))
repl.put(str.toLowerCase(Locale.US), ""); map.put(env, "");
String lower_env = env.toLowerCase(Locale.US);
if(map.containsKey(lower_env))
map.put(lower_env, "");
} }
} }
public static void checkDangerousParametrs() { public static void checkDangerousParams() {
for (String t : toTest) for (String t : toTest) {
if (System.getenv(t) != null) { String env = System.getenv(t);
String env = System.getenv(t).toLowerCase(Locale.US); if (env != null) {
env = env.toLowerCase(Locale.US);
if (env.contains("-cp") || env.contains("-classpath") || env.contains("-javaagent") if (env.contains("-cp") || env.contains("-classpath") || env.contains("-javaagent")
|| env.contains("-agentpath") || env.contains("-agentlib")) || env.contains("-agentpath") || env.contains("-agentlib"))
throw new SecurityException("JavaAgent in global optings not allow"); throw new SecurityException("JavaAgent in global options not allow");
} }
}
} }
} }