mirror of https://github.com/rwf2/Rocket.git
Fuzz URI parsing and display.
This commit is contained in:
parent
0d53e23bf6
commit
94a5f5eca6
|
@ -0,0 +1,4 @@
|
|||
target
|
||||
corpus/*/*
|
||||
artifacts
|
||||
!*.seed
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
[package]
|
||||
name = "rocket-fuzz"
|
||||
version = "0.0.0"
|
||||
authors = ["Automatically generated"]
|
||||
publish = false
|
||||
edition = "2018"
|
||||
|
||||
[package.metadata]
|
||||
cargo-fuzz = true
|
||||
|
||||
[dependencies]
|
||||
libfuzzer-sys = "0.4"
|
||||
|
||||
[dependencies.rocket]
|
||||
path = ".."
|
||||
|
||||
# Prevent this from interfering with workspaces
|
||||
[workspace]
|
||||
members = ["."]
|
||||
|
||||
[[bin]]
|
||||
name = "uri-parsing"
|
||||
path = "targets/uri-parsing.rs"
|
||||
test = false
|
||||
doc = false
|
||||
|
||||
[[bin]]
|
||||
name = "uri-roundtrip"
|
||||
path = "targets/uri-roundtrip.rs"
|
||||
test = false
|
||||
doc = false
|
|
@ -0,0 +1,15 @@
|
|||
# Fuzzing
|
||||
|
||||
Install `cargo-fuzz`:
|
||||
|
||||
```sh
|
||||
cargo install -f cargo-fuzz
|
||||
```
|
||||
|
||||
Run any available target where `$target` is the name of the target and `$n` is
|
||||
the number of CPUs to use for fuzzing:
|
||||
|
||||
```sh
|
||||
cargo fuzz list # get list of targets
|
||||
cargo fuzz run $target -j $n
|
||||
```
|
|
@ -0,0 +1 @@
|
|||
http://user:pass@domain.com:4444/foo/bar?some=query
|
|
@ -0,0 +1 @@
|
|||
*
|
|
@ -0,0 +1 @@
|
|||
username:password@some.host:8088
|
|
@ -0,0 +1 @@
|
|||
/first_segment/second_segment/third?optional=query
|
|
@ -0,0 +1 @@
|
|||
http://user:pass@domain.com:4444/foo/bar?some=query#and-fragment
|
|
@ -0,0 +1,22 @@
|
|||
#![no_main]
|
||||
|
||||
use rocket::http::uri::*;
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
|
||||
fn fuzz(data: &str) {
|
||||
// Fuzz the top-level parser.
|
||||
if let Ok(uri) = Uri::parse_any(data) {
|
||||
// Ensure Uri::parse::<T>() => T::parse().
|
||||
match uri {
|
||||
Uri::Asterisk(_) => { Asterisk::parse(data).expect("Asterisk"); },
|
||||
Uri::Origin(_) => { Origin::parse(data).expect("Origin"); },
|
||||
Uri::Authority(_) => { Authority::parse(data).expect("Authority"); },
|
||||
Uri::Absolute(_) => { Absolute::parse(data).expect("Absolute"); },
|
||||
Uri::Reference(_) => { Reference::parse(data).expect("Reference"); },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let _ = std::str::from_utf8(data).map(fuzz);
|
||||
});
|
|
@ -0,0 +1,21 @@
|
|||
#![no_main]
|
||||
|
||||
use rocket::http::uri::*;
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
|
||||
fn fuzz(data: &str) {
|
||||
if let Ok(uri) = Uri::parse_any(data) {
|
||||
let string = uri.to_string();
|
||||
let _ = match uri {
|
||||
Uri::Asterisk(_) => Asterisk::parse_owned(string).expect("Asterisk").to_string(),
|
||||
Uri::Origin(_) => Origin::parse_owned(string).expect("Origin").to_string(),
|
||||
Uri::Authority(_) => Authority::parse_owned(string).expect("Authority").to_string(),
|
||||
Uri::Absolute(_) => Absolute::parse_owned(string).expect("Absolute").to_string(),
|
||||
Uri::Reference(_) => Reference::parse_owned(string).expect("Reference").to_string(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let _ = std::str::from_utf8(data).map(fuzz);
|
||||
});
|
Loading…
Reference in New Issue