diff --git a/fuzz/.gitignore b/fuzz/.gitignore new file mode 100644 index 0000000..1a45eee --- /dev/null +++ b/fuzz/.gitignore @@ -0,0 +1,4 @@ +target +corpus +artifacts +coverage diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 0000000..5e74f15 --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "urlpattern-fuzz" +version = "0.0.0" +publish = false +edition = "2021" + +[package.metadata] +cargo-fuzz = true + +[dependencies] +libfuzzer-sys = "0.4" +arbitrary = { version = "1", features = ["derive"] } +regex = "1" + +[dependencies.urlpattern] +path = ".." + +[[bin]] +name = "fuzz_parse" +path = "fuzz_targets/fuzz_parse.rs" +test = false +doc = false +bench = false diff --git a/fuzz/fuzz_targets/fuzz_parse.rs b/fuzz/fuzz_targets/fuzz_parse.rs new file mode 100644 index 0000000..d960e00 --- /dev/null +++ b/fuzz/fuzz_targets/fuzz_parse.rs @@ -0,0 +1,36 @@ +#![no_main] +use urlpattern::{UrlPattern, UrlPatternInit, UrlPatternOptions}; +use libfuzzer_sys::arbitrary::Arbitrary; +use libfuzzer_sys::fuzz_target; + +#[derive(Arbitrary, Debug)] +struct FuzzInput { + protocol: Option, + username: Option, + password: Option, + hostname: Option, + port: Option, + pathname: Option, + search: Option, + hash: Option, + base_url: Option, + ignore_case: bool, +} + +fuzz_target!(|input: FuzzInput| { + let init = UrlPatternInit { + protocol: input.protocol, + username: input.username, + password: input.password, + hostname: input.hostname, + port: input.port, + pathname: input.pathname, + search: input.search, + hash: input.hash, + base_url: input.base_url.and_then(|s| s.parse().ok()), + }; + let options = UrlPatternOptions { + ignore_case: input.ignore_case, + }; + let _ = UrlPattern::::parse(init, options); +});