From 4e75894438d099411ea60c4db62be604805159ad Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 22 Oct 2018 14:15:44 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D1=87=D0=B8=D1=82?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=20=D0=BE=D1=81=D0=BD=D0=BE=D0=B2=D0=B5=20?= =?UTF-8?q?=D0=B3=D0=BB=D0=BE=D0=B1=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D1=87=D0=B0=D1=81=D1=82=D1=8C=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/utils/helper/EnvHelper.java | 63 ++++--------------- 1 file changed, 11 insertions(+), 52 deletions(-) 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 9e6d20a9..a64b466a 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/EnvHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/EnvHelper.java @@ -7,68 +7,27 @@ import java.util.regex.Pattern; public class EnvHelper { - private static final boolean TST; - private static final boolean HASXW; public static final String[] toTest; - public static final Pattern[] test; static { toTest = new String[] { "_JAVA_OPTIONS", "_JAVA_OPTS", "JAVA_OPTS", "JAVA_OPTIONS" }; - test = new Pattern[] { Pattern.compile("-xm.*\\d+[KMG]") }; - TST = check0(); - HASXW = check1(); } public static void addEnv(ProcessBuilder builder) { - if (hasOptsEnv()) { - Map repl = new HashMap<>(); - for (String str : toTest) { - repl.put(str, ""); - repl.put(str.toLowerCase(Locale.US), ""); - } - JVMHelper.appendVars(builder, repl); + Map repl = builder.environment(); + for (String str : toTest) { + repl.put(str, ""); + repl.put(str.toLowerCase(Locale.US), ""); } } - private static boolean check0() { - for (String test : toTest) - if (System.getProperty(test) != null) - return true; - return false; - } - - /** - * Вынужденное решение ибо тест на наличие -Xm* этакой нужен. - */ - private static boolean check1() { - if (hasOptsEnv()) - for (String testStr : toTest) - if (System.getenv(testStr) != null) { - String str = System.getenv(testStr).toLowerCase(Locale.US); - StringTokenizer st = new StringTokenizer(str); - while (st.hasMoreTokens()) - if (CommonHelper.multiMatches(test, st.nextToken())) - return true; - } - return false; - } - public static void checkDangerousParametrs() { - if (hasOptsEnv()) - for (String t : toTest) - if (System.getenv(t) != null) { - String env = System.getenv(t).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"); - } - } - - public static boolean hasOptsEnv() { - return TST; - } - - public static boolean hasWarnPreDef() { - return HASXW; + for (String t : toTest) + if (System.getenv(t) != null) { + String env = System.getenv(t).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"); + } } }