From 23f67c2160b7d87c64bce8f3ea4d9593c78927f5 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 26 Oct 2018 21:42:20 +0700 Subject: [PATCH] =?UTF-8?q?CodeStyle=20=D0=B4=D0=BB=D1=8F=20EnvHelper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/ClientLauncherWrapper.java | 2 +- .../ru/gravit/launcher/LauncherEngine.java | 3 +-- .../launcher/client/ClientLauncher.java | 2 +- .../ru/gravit/utils/helper/EnvHelper.java | 23 +++++++++++-------- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java index 2ebcd25c..fac29ef1 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java @@ -19,7 +19,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep LogHelper.printVersion("Launcher"); JVMHelper.checkStackTrace(ClientLauncherWrapper.class); JVMHelper.verifySystemProperties(Launcher.class, true); - EnvHelper.checkDangerousParametrs(); + EnvHelper.checkDangerousParams(); LogHelper.debug("Restart Launcher"); ProcessBuilder processBuilder = new ProcessBuilder(); processBuilder.inheritIO(); diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index 994cc45d..d193ead4 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -42,7 +42,6 @@ import ru.gravit.launcher.request.auth.AuthRequest; import ru.gravit.launcher.request.auth.CheckServerRequest; 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.uuid.BatchProfileByUsernameRequest; import ru.gravit.launcher.request.uuid.ProfileByUUIDRequest; @@ -151,7 +150,7 @@ public static void addLauncherClassBindings(Map bindings) { public static void main(String... args) throws Throwable { JVMHelper.checkStackTrace(LauncherEngine.class); JVMHelper.verifySystemProperties(Launcher.class, true); - EnvHelper.checkDangerousParametrs(); + EnvHelper.checkDangerousParams(); if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set"); LogHelper.printVersion("Launcher"); // Start Launcher diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java index 37794b35..1d4c1adb 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -407,7 +407,7 @@ public static void main(String... args) throws Throwable { } checkJVMBitsAndVersion(); JVMHelper.verifySystemProperties(ClientLauncher.class, true); - EnvHelper.checkDangerousParametrs(); + EnvHelper.checkDangerousParams(); JVMHelper.checkStackTrace(ClientLauncher.class); LogHelper.printVersion("Client Launcher"); // Read and delete params file diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/EnvHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/EnvHelper.java index a64b466a..1b703ae1 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/EnvHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/EnvHelper.java @@ -14,20 +14,25 @@ public class EnvHelper { } public static void addEnv(ProcessBuilder builder) { - Map repl = builder.environment(); - for (String str : toTest) { - repl.put(str, ""); - repl.put(str.toLowerCase(Locale.US), ""); + Map map = builder.environment(); + for (String env : toTest) { + if(map.containsKey(env)) + map.put(env, ""); + String lower_env = env.toLowerCase(Locale.US); + if(map.containsKey(lower_env)) + map.put(lower_env, ""); } } - public static void checkDangerousParametrs() { - for (String t : toTest) - if (System.getenv(t) != null) { - String env = System.getenv(t).toLowerCase(Locale.US); + public static void checkDangerousParams() { + for (String t : toTest) { + String env = System.getenv(t); + if (env != null) { + env = env.toLowerCase(Locale.US); if (env.contains("-cp") || env.contains("-classpath") || env.contains("-javaagent") || env.contains("-agentpath") || env.contains("-agentlib")) - throw new SecurityException("JavaAgent in global optings not allow"); + throw new SecurityException("JavaAgent in global options not allow"); } + } } }