Skip to content

Commit

Permalink
Update fuzz crate
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
e00E committed Dec 14, 2020
1 parent 98a9c07 commit 2eee845
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
12 changes: 8 additions & 4 deletions url/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,9 +15,12 @@ libfuzzer-sys = "0.3"
[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
15 changes: 6 additions & 9 deletions url/fuzz/fuzz_targets/parse.rs
Original file line number Diff line number Diff line change
@@ -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);
}
});

0 comments on commit 2eee845

Please sign in to comment.