Skip to content

Commit

Permalink
Null injection hardening (Adds tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
benhumphreys-atlassian committed Sep 19, 2022
1 parent fabf505 commit 467b28a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/test/java/com/zaxxer/nuprocess/RunTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,32 @@ public void softCloseStdinAfterWrite()
System.err.println("Completed test softCloseStdinAfterWrite()");
}

@Test(expected = IllegalArgumentException.class)
public void nullCommandViaCommandMutationWithRun() {
NuProcessBuilder pb = new NuProcessBuilder(new NullProcessHandler(), command);
pb.command().add("--foo\0--bar");
pb.run();
}

@Test(expected = IllegalArgumentException.class)
public void nullCommandViaCommandMutationWithStart() {
NuProcessBuilder pb = new NuProcessBuilder(new NullProcessHandler(), command);
pb.command().add("--foo\0--bar");
pb.start();
}

@Test(expected = IllegalArgumentException.class)
public void nullCommandViaConstructorWithRun() {
NuProcessBuilder pb = new NuProcessBuilder(new NullProcessHandler(), command, "--foo\0--bar");
pb.run();
}

@Test(expected = IllegalArgumentException.class)
public void nullCommandViaConstructorWithStart() {
NuProcessBuilder pb = new NuProcessBuilder(new NullProcessHandler(), command, "--foo\0--bar");
pb.start();
}

private static byte[] getLotsOfBytes()
{
StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -395,6 +421,9 @@ boolean checkAdlers()
}
}

private static class NullProcessHandler extends NuAbstractProcessHandler {
}

private static class Utf8DecodingListener extends NuAbstractCharsetHandler
{
private final CharBuffer utf8Buffer;
Expand Down

0 comments on commit 467b28a

Please sign in to comment.