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

OSS-Fuzz: Add more fuzzer #988

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions url/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@ path = ".."
name = "parse"
path = "fuzz_targets/parse.rs"

[[bin]]
name = "fuzz-url"
path = "fuzz_targets/fuzz-url.rs"

[workspace]
members = ["."]
129 changes: 129 additions & 0 deletions url/fuzz/fuzz_targets/fuzz-url.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#![no_main]
#[macro_use]
extern crate libfuzzer_sys;
extern crate url;

use std::str;
use url::{Url, quirks, Origin, Host, Position};

fuzz_target!(|data: &[u8]| {
// Initialisation
let utf8 = match str::from_utf8(data) {
Ok(v) => v,
Err(_) => return,
};
let mut url_parse_attempt = Url::parse(utf8);

// Randomly fuzz functions
match data.get(0) {
Some(&choice) => match choice % 20 {
0 => {
if let Ok(parsed_url) = &url_parse_attempt {
let _ = parsed_url.query();
}
},
1 => {
if let Ok(parsed_url) = &url_parse_attempt {
let _ = parsed_url.fragment();
}
},
2 => {
if let Ok(parsed_url) = &mut url_parse_attempt {
let _ = quirks::set_protocol(parsed_url, utf8);
}
},
3 => {
if let Ok(parsed_url) = &mut url_parse_attempt {
let _ = quirks::set_username(parsed_url, utf8);
}
},
4 => {
if let Ok(parsed_url) = &mut url_parse_attempt {
let _ = quirks::set_password(parsed_url, utf8);
}
},
5 => {
if let Ok(parsed_url) = &mut url_parse_attempt {
quirks::set_search(parsed_url, utf8);
}
},
6 => {
if let Ok(parsed_url) = &mut url_parse_attempt {
quirks::set_hash(parsed_url, utf8);
}
},
7 => {
if let Ok(parsed_url) = &mut url_parse_attempt {
parsed_url.set_scheme("https").ok();
}
},
8 => {
if let Ok(parsed_url) = &mut url_parse_attempt {
let _ = parsed_url.set_host(Some("example.com"));
}
},
9 => {
if let Ok(parsed_url) = &mut url_parse_attempt {
let _ = parsed_url.set_port(Some(8080));
}
},
10 => {
if let Ok(parsed_url) = &mut url_parse_attempt {
let _ = parsed_url.set_path("/test/path");
}
},
11 => {
if let Ok(parsed_url) = &mut url_parse_attempt {
let _ = parsed_url.path_segments_mut().map(|mut segments| {
segments.push("segment1");
segments.push("segment2");
});
}
},
12 => {
if let Ok(parsed_url) = &mut url_parse_attempt {
let _ = parsed_url.set_query(Some("key=value"));
}
},
13 => {
if let Ok(parsed_url) = &mut url_parse_attempt {
let _ = parsed_url.set_fragment(Some("fragment"));
}
},
14 => {
if let Ok(parsed_url) = &url_parse_attempt {
if let Some(domain) = parsed_url.host_str() {
let _ = Host::parse(domain);
}
}
},
15 => {
if let Ok(parsed_url) = &url_parse_attempt {
let _ = parsed_url.origin().ascii_serialization();
}
},
16 => {
if let Ok(parsed_url) = &mut url_parse_attempt {
let _ = parsed_url.join("/relative/path");
}
},
17 => {
if let Ok(parsed_url) = &mut url_parse_attempt {
let _ = parsed_url.make_relative(&Url::parse("https://example.com/base").unwrap());
}
},
18 => {
if let Ok(parsed_url) = &url_parse_attempt {
let _ = &parsed_url[Position::BeforeHost..Position::AfterPort];
}
},
19 => {
if let Ok(parsed_url) = &url_parse_attempt {
let _ = &parsed_url[Position::BeforeScheme..];
}
},
_ => {},
},
None => {},
}
});
Loading