From 9aedd87d8852d2da5f77be446855b06d0f646b03 Mon Sep 17 00:00:00 2001 From: Arthur Chan Date: Fri, 7 Feb 2025 11:39:42 +0000 Subject: [PATCH 1/2] from_scratch: Fix README.md Signed-off-by: Arthur Chan --- experimental/from_scratch/README.md | 55 ++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/experimental/from_scratch/README.md b/experimental/from_scratch/README.md index cfbf959f6..a85afef31 100644 --- a/experimental/from_scratch/README.md +++ b/experimental/from_scratch/README.md @@ -18,23 +18,36 @@ python3 -m pip install -e . cd ../../ # Prepare a target +## C++ git clone https://github.com/dvhar/dateparse +## Java +git clone https://github.com/stleary/JSON-java json-java # Clone oss-fuzz-gen git clone https://github.com/google/oss-fuzz-gen cd oss-fuzz-gen python3 -m pip install -r ./requirements.txt -# Generate a harness +# Generate a harness (C++) (with function name) python3 -m experimental.from_scratch.generate \ -e c++ \ -l ${MODEL} \ -f dateparse \ - -t ../dateparse/ + -t ../dateparse/ \ + -r responses_cpp + +# Generate a harness (Java) (with source file and line) +python3 -m experimental.from_scratch.generate \ + -e java \ + -l ${MODEL} \ + -s JSONArray.java \ + -sl 1200 \ + -t ../json-java/ \ + -r responses_java # Show harness -cat responses/01.rawoutput -""" +cat responses_cpp/01.rawoutput +``` #include #include @@ -58,5 +71,37 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { free(datestr); return 0; } -""" +``` + +cat responses_java/01.rawoutput +```java +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import org.json.JSONArray; + +public class JSONArray { + public static void fuzzerInitialize() { + // Initializing objects for fuzzing + } + + public static void fuzzerTearDown() { + // Tear down objects after fuzzing + } + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + boolean bool = data.consumeBoolean(); + + JSONArray jsonArray = new JSONArray(); + try { + jsonArray.put(bool); + } catch (RuntimeException e) { + // Catch potential RuntimeException + } finally { + try { + jsonArray.close(); + } catch (Exception ignored) { + // Ignoring any exception in closing the resource + } + } + } +} ``` From 7833285a8cbe48a94aff2905ed90597346578496 Mon Sep 17 00:00:00 2001 From: Arthur Chan Date: Fri, 7 Feb 2025 11:44:52 +0000 Subject: [PATCH 2/2] Fix formatting Signed-off-by: Arthur Chan --- experimental/from_scratch/README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/experimental/from_scratch/README.md b/experimental/from_scratch/README.md index a85afef31..47a347710 100644 --- a/experimental/from_scratch/README.md +++ b/experimental/from_scratch/README.md @@ -47,7 +47,7 @@ python3 -m experimental.from_scratch.generate \ # Show harness cat responses_cpp/01.rawoutput -``` +""" #include #include @@ -71,10 +71,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { free(datestr); return 0; } -``` +""" cat responses_java/01.rawoutput -```java +""" import com.code_intelligence.jazzer.api.FuzzedDataProvider; import org.json.JSONArray; @@ -104,4 +104,6 @@ public class JSONArray { } } } +""" ``` +