Skip to content

Commit

Permalink
Merge branch 'main' into idna-v1x
Browse files Browse the repository at this point in the history
  • Loading branch information
hsivonen authored Nov 4, 2024
2 parents 7ead88b + 08a3268 commit 6811cbe
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
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 => {},
}
});

0 comments on commit 6811cbe

Please sign in to comment.