-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from zi0Black/support-for-LLVMFuzzerInitialize
Introduce LLVMFuzzerInitialize support
- Loading branch information
Showing
9 changed files
with
154 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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