Ghidra is a software reverse engineering (SRE) framework
GP-6022: Better error reporting when expanding environment variables in launch.properties
Ryan Kurtzaef70ea9becc
diff --git a/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/LaunchProperties.java b/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/LaunchProperties.javaindex 92fb71359d..c3822b9d9e 100644--- a/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/LaunchProperties.java+++ b/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/LaunchProperties.java@@ -182,14 +182,23 @@ public class LaunchProperties {** @param text The string to expand environment variables in* @return The given string, but with set environment variables expanded+ * @throws ParseException if there was a problem expanding an environment variable*/- private static String expandEnvVars(String text) {+ private static String expandEnvVars(String text) throws ParseException {Map<String, String> envMap = System.getenv();- for (Entry<String, String> entry : envMap.entrySet()) {- String key = entry.getKey();- String value = entry.getValue();- text = text.replaceAll("\\$\\{" + key + "\\}", value.replace("\\", "\\\\"));- }- return text;- }+ for (Entry<String, String> entry : envMap.entrySet()) {+ String key = entry.getKey();+ String value = entry.getValue();+ try {+ text = text.replaceAll("\\$\\{" + key + "\\}", value.replace("\\", "\\\\"));+ }+ catch (IllegalArgumentException e) {+ throw new ParseException(+ "Error expanding environment variable in %s (env %s=%s) -- %s".formatted(text,+ key, value, e.getMessage()),+ 0);+ }+ }+ return text;+ }}