diff --git a/src/main/java/com/zaxxer/nuprocess/NuProcessBuilder.java b/src/main/java/com/zaxxer/nuprocess/NuProcessBuilder.java index d0276ec..ae4c490 100644 --- a/src/main/java/com/zaxxer/nuprocess/NuProcessBuilder.java +++ b/src/main/java/com/zaxxer/nuprocess/NuProcessBuilder.java @@ -107,6 +107,7 @@ public NuProcessBuilder(List commands, Map environment) if (commands == null || commands.isEmpty()) { throw new IllegalArgumentException("List of commands may not be null or empty"); } + ensureNoNullCharacters(commands); this.environment = new TreeMap(environment); this.command = new ArrayList(commands); @@ -126,6 +127,7 @@ public NuProcessBuilder(List commands) if (commands == null || commands.isEmpty()) { throw new IllegalArgumentException("List of commands may not be null or empty"); } + ensureNoNullCharacters(commands); this.environment = new TreeMap(System.getenv()); this.command = new ArrayList(commands); @@ -144,9 +146,11 @@ public NuProcessBuilder(String... commands) if (commands == null || commands.length == 0) { throw new IllegalArgumentException("List of commands may not be null or empty"); } + List commandsList = Arrays.asList(commands); + ensureNoNullCharacters(commandsList); this.environment = new TreeMap(System.getenv()); - this.command = new ArrayList(Arrays.asList(commands)); + this.command = new ArrayList(commandsList); } /** @@ -280,6 +284,14 @@ private void ensureListener() } } + private void ensureNoNullCharacters(List commands) { + for (String command : commands) { + if (command.indexOf('\u0000') >= 0) { + throw new IllegalArgumentException("Commands may not contain null characters"); + } + } + } + private String[] prepareEnvironment() { String[] env = new String[environment.size()];