-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
14 additions
and
13 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
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); | ||
} | ||
}); |