diff --git a/fuzz/.gitignore b/fuzz/.gitignore index 08ba2bbe..572e03bd 100644 --- a/fuzz/.gitignore +++ b/fuzz/.gitignore @@ -1,3 +1,4 @@ target -libfuzzer +corpus +artifacts diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 0443d5ed..0b108b95 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -3,9 +3,15 @@ name = "url-fuzz" version = "0.0.1" authors = ["Automatically generated"] +publish = false + +[package.metadata] +cargo-fuzz = true [dependencies.url] path = ".." +[dependencies.libfuzzer-sys] +git = "https://github.com/rust-fuzz/libfuzzer-sys.git" [[bin]] name = "parse" diff --git a/fuzz/fuzzers/parse.rs b/fuzz/fuzzers/parse.rs index f9ff8e37..cf15cd06 100644 --- a/fuzz/fuzzers/parse.rs +++ b/fuzz/fuzzers/parse.rs @@ -1,16 +1,10 @@ #![no_main] - -extern crate libfuzzer_sys; - +#[macro_use] extern crate libfuzzer_sys; extern crate url; -use std::slice; use std::str; -#[export_name="LLVMFuzzerTestOneInput"] -pub extern fn go(data: *const u8, size: isize) -> i32 { - let slice = unsafe { slice::from_raw_parts(data, size as usize) }; - if let Ok(utf8) = str::from_utf8(slice) { +fuzz_target!(|data: &[u8]| { + if let Ok(utf8) = str::from_utf8(data) { let url = url::Url::parse(utf8); } - return 0; -} +});