-
Notifications
You must be signed in to change notification settings - Fork 49
Introduce LLVMFuzzerInitialize support #128
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
Merged
fitzgen
merged 12 commits into
rust-fuzz:main
from
zi0Black:support-for-LLVMFuzzerInitialize
Jan 24, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d561921
Enhance fuzzing capabilities with LLVMFuzzerInitialize support
zi0Black e793413
Better example using static
zi0Black ba4ad43
Refactoring
zi0Black 005c428
Restore missing comments
zi0Black c283757
Update src/lib.rs
zi0Black 006af93
fmt
zi0Black 8188902
fixed type in doc
zi0Black 162e810
Revert "fixed type in doc"
zi0Black 36f2c11
Fixed compatibility with short |input|
zi0Black 57296bf
Update init doc
zi0Black 916627d
fix doc
zi0Black 55cb6cd
fmt
zi0Black File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
crash-* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[package] | ||
name = "example_init" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "example_init-fuzz" | ||
version = "0.1.0" | ||
authors = ["Andrea Cappa"] | ||
edition = "2018" | ||
|
||
[package.metadata] | ||
cargo-fuzz = true | ||
|
||
[dependencies] | ||
libfuzzer-sys = { path = "../.." } | ||
example_init = { path = ".." } | ||
|
||
[[bin]] | ||
name = "bigbang" | ||
path = "fuzz_targets/bigbang.rs" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#![no_main] | ||
|
||
use libfuzzer_sys::fuzz_target; | ||
|
||
fuzz_target!( | ||
init: { | ||
// Custom initialization code here | ||
println!("Initializing fuzzer..."); | ||
example_init::initialize(); | ||
}, | ||
|data: &[u8]| { | ||
example_init::bigbang(data); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::sync::OnceLock; | ||
|
||
static EXTRA_DATA: OnceLock<&'static str> = OnceLock::new(); | ||
|
||
pub fn bigbang(data: &[u8]) { | ||
// The fuzzer needs to mutate input to be "bigbang!" | ||
// Init needs to be called before bigbang() is called | ||
// This actually proves that the fuzzer is calling init before bigbang | ||
if data == &b"bigbang!"[..] && is_initialized() { | ||
panic!("bigbang!"); | ||
} | ||
} | ||
|
||
pub fn initialize() { | ||
EXTRA_DATA | ||
.set("initialized") | ||
.expect("should only initialize once"); | ||
} | ||
|
||
pub fn is_initialized() -> bool { | ||
EXTRA_DATA.get().is_some() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.