Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from_scratch: Fix README.md #783

Merged
merged 3 commits into from
Feb 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 50 additions & 3 deletions experimental/from_scratch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,35 @@ 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 <stdio.h>
#include <string.h>
Expand All @@ -59,4 +72,38 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
return 0;
}
"""

cat responses_java/01.rawoutput
"""
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
}
}
}
}
"""
```