From 55e65d07e66658c9c789f58e3d5a134f0156491b Mon Sep 17 00:00:00 2001 From: Valentin Date: Thu, 10 Dec 2020 16:29:02 +0100 Subject: [PATCH] Update fuzz crate Following the instructions from the fuzzing book the fuzz crate has been recreated. Putting the second parse and the assert on different lines gives better panic messages because it makes it easier to distinguish whether the unwrapping or the assert failed. --- url/fuzz/Cargo.toml | 12 ++++++++---- url/fuzz/fuzz_targets/parse.rs | 15 ++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/url/fuzz/Cargo.toml b/url/fuzz/Cargo.toml index 1d841abb7..3d808ac4f 100644 --- a/url/fuzz/Cargo.toml +++ b/url/fuzz/Cargo.toml @@ -1,9 +1,10 @@ [package] name = "url-fuzz" -version = "0.0.1" +version = "0.0.0" authors = ["Automatically generated"] publish = false +edition = "2018" [package.metadata] cargo-fuzz = true @@ -14,9 +15,12 @@ libfuzzer-sys = "0.4.0" [dependencies.url] path = ".." +# Prevent this from interfering with workspaces +[workspace] +members = ["."] + [[bin]] name = "parse" path = "fuzz_targets/parse.rs" - -[workspace] -members = ["."] +test = false +doc = false diff --git a/url/fuzz/fuzz_targets/parse.rs b/url/fuzz/fuzz_targets/parse.rs index 1797f6ae3..65b9543ac 100644 --- a/url/fuzz/fuzz_targets/parse.rs +++ b/url/fuzz/fuzz_targets/parse.rs @@ -1,13 +1,10 @@ #![no_main] -#[macro_use] extern crate libfuzzer_sys; -extern crate url; -use std::str; +use libfuzzer_sys::fuzz_target; -fuzz_target!(|data: &[u8]| { - if let Ok(utf8) = str::from_utf8(data) { - if let Ok(parsed) = url::Url::parse(utf8) { - let as_str = parsed.as_str(); - assert_eq!(parsed, url::Url::parse(as_str).unwrap()); - } +fuzz_target!(|data: String| { + if let Ok(parsed) = url::Url::parse(data.as_str()) { + let as_str = parsed.as_str(); + let parsed_again = url::Url::parse(as_str).unwrap(); + assert_eq!(parsed, parsed_again); } });