From 8aa3d3c16f97c5be054e9990830289c28b3f60d4 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Tue, 30 Nov 2021 12:25:41 +0100 Subject: Ensure that escapes are honored by fork and merge Fixes https://github.com/google/oss-fuzz/issues/6926. --- examples/BUILD.bazel | 6 ++++-- examples/src/main/java/com/example/JpegImageParserFuzzer.java | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel index 92c07e09..06f0d2a0 100644 --- a/examples/BUILD.bazel +++ b/examples/BUILD.bazel @@ -111,8 +111,10 @@ java_fuzz_target_test( "-fork=5", "--additional_jvm_args=-Dbaz=baz", ] + select({ - "@platforms//os:windows": ["--jvm_args=-Dfoo=foo;-Dbar=bar"], - "//conditions:default": ["--jvm_args=-Dfoo=foo:-Dbar=bar"], + # \\\\ becomes \\ when evaluated as a Starlark string literal, then \ in + # java_fuzz_target_test. + "@platforms//os:windows": ["--jvm_args=-Dfoo=foo;-Dbar=b\\\\;ar"], + "//conditions:default": ["--jvm_args=-Dfoo=foo:-Dbar=b\\\\:ar"], }), target_class = "com.example.JpegImageParserFuzzer", # The exit codes of the forked libFuzzer processes are not picked up correctly. diff --git a/examples/src/main/java/com/example/JpegImageParserFuzzer.java b/examples/src/main/java/com/example/JpegImageParserFuzzer.java index 84a1029a..a6898bf0 100644 --- a/examples/src/main/java/com/example/JpegImageParserFuzzer.java +++ b/examples/src/main/java/com/example/JpegImageParserFuzzer.java @@ -23,11 +23,15 @@ import org.apache.commons.imaging.formats.jpeg.JpegImageParser; // Found https://issues.apache.org/jira/browse/IMAGING-275. public class JpegImageParserFuzzer { public static void fuzzerInitialize() { + String foo = System.getProperty("foo"); + String bar = System.getProperty("bar"); + String baz = System.getProperty("baz"); // Only used to verify that arguments are correctly passed down to child processes. - if (System.getProperty("foo") == null || System.getProperty("bar") == null - || System.getProperty("baz") == null) { + if (foo == null || bar == null || baz == null || !foo.equals("foo") + || !(bar.equals("b;ar") || bar.equals("b:ar")) || !baz.equals("baz")) { // Exit the process with an exit code different from that for a finding. - System.err.println("ERROR: Did not pass all jvm_args to child process."); + System.err.println("ERROR: Did not correctly pass all jvm_args to child process."); + System.err.printf("foo: %s%nbar: %s%nbaz: %s%n", foo, bar, baz); System.exit(3); } } -- cgit v1.2.3