diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | java/lang/System.java | 30 |
2 files changed, 24 insertions, 11 deletions
@@ -1,3 +1,8 @@ +2008-09-16 Mario Torre <neugens@aicas.com> + + * java/lang/System.java (getenv): Fix env entries of the form + key=value=value=value not parsed correctly. + 2008-09-15 Andrew John Hughes <gnu_andrew@member.fsf.org> Reported by: Matthias Klose diff --git a/java/lang/System.java b/java/lang/System.java index 9fd6bfe12..6be313155 100644 --- a/java/lang/System.java +++ b/java/lang/System.java @@ -546,20 +546,28 @@ public final class System SecurityManager sm = SecurityManager.current; // Be thread-safe. if (sm != null) sm.checkPermission(new RuntimePermission("getenv.*")); + if (environmentMap == null) { - List<String> environ = (List<String>)VMSystem.environ(); - Map<String,String> variables = new EnvironmentMap(); - for (String pair : environ) - { - String[] parts = pair.split("="); - if (parts.length == 2) - variables.put(parts[0], parts[1]); - else - variables.put(parts[0], ""); - } - environmentMap = Collections.unmodifiableMap(variables); + Map<String, String> _map = new HashMap(); + List<String> environ = (List<String>)VMSystem.environ(); + for (String envEntry : environ) + { + // avoid broken and null entries + if (envEntry != null && !envEntry.endsWith("=")) + { + // it's perfectly legal that some entries may be in the form + // key=value=value=value + int equalSignIndex = envEntry.indexOf('='); + String key = envEntry.substring(0, equalSignIndex); + String value = envEntry.substring(equalSignIndex + 1); + _map.put(key, value); + } + } + + environmentMap = Collections.unmodifiableMap(_map); } + return environmentMap; } |