Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuzzing #84

Merged
merged 7 commits into from Apr 6, 2020
Prev

fuzzing request parsing

  • Loading branch information
AndriusA committed Mar 30, 2020
commit 8a4e9042e6be7751e620d0a977d2e0471a2c7de7
@@ -22,3 +22,7 @@ members = ["."]
[[bin]]
name = "parse_filter"
path = "fuzz_targets/parse_filter.rs"

[[bin]]
name = "parse_request"
path = "fuzz_targets/parse_request.rs"
@@ -0,0 +1,13 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
use adblock::request::Request;

fuzz_target!(|data: &[u8]| {
if let Ok(url) = std::str::from_utf8(data) {
Request::from_url(&format!("https://{}", url));
Request::from_urls(url, "https://example.com", "script");
Request::from_urls(url, "", "");
Request::from_urls(url, url, "");
Request::from_urls(url, url, url);
}
});
@@ -534,4 +534,17 @@ mod tests {
assert_eq!(parsed.is_third_party, Some(false));
}
}

#[test]
fn fuzzing_errors() {
{
let parsed = Request::from_url("https://߶");
assert!(parsed.is_ok());
}
{
let parsed = Request::from_url(
&format!("https://{}", std::str::from_utf8(&[9, 9, 64]).unwrap()));
assert!(parsed.is_err());
}
}
}
@@ -40,7 +40,7 @@ impl UrlParser for Request {
url: h.url_str().to_owned(),
schema_end: h.scheme_end,
hostname_pos: (h.host_start, h.host_end),
domain: get_host_domain(&url[h.host_start..h.host_end])
domain: get_host_domain(&h.url_str()[h.host_start..h.host_end])
}),
_ => None
}
@@ -189,6 +189,7 @@ simple_enum_error! {
// SetHostOnCannotBeABaseUrl => "a cannot-be-a-base URL doesn’t have a host to set",
// Overflow => "URLs more than 4 GB are not supported",
FileUrlNotSupported => "file URLs are not supported",
ExpectedMoreChars => "Expected more characters",
}

#[cfg(feature = "heapsize")]
@@ -454,7 +455,7 @@ impl Parser {
let mut has_password = false;
let mut has_username = false;
while userinfo_char_count > 0 {
let (c, utf8_c) = input.next_utf8().unwrap();
let (c, utf8_c) = input.next_utf8().ok_or(ParseError::ExpectedMoreChars)?;
userinfo_char_count -= 1;
if c == ':' && username_end.is_none() {
// Start parsing password
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.