Skip to content

Commit 5e84453

Browse files
authored
Merge pull request #1209 from silvergasp/fuzz-gix-url
Fuzz more of gix_url::Url
2 parents 0f71709 + 8d4f9d7 commit 5e84453

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

gix-url/fuzz/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ edition = "2021"
99
cargo-fuzz = true
1010

1111
[dependencies]
12+
anyhow = "1.0.76"
1213
libfuzzer-sys = "0.4"
1314

1415
[dependencies.gix-url]

gix-url/fuzz/fuzz_targets/parse.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
#![no_main]
2+
use anyhow::Result;
23
use libfuzzer_sys::fuzz_target;
4+
use std::hint::black_box;
5+
use std::path::Path;
6+
7+
fn fuzz(data: &[u8]) -> Result<()> {
8+
let url = gix_url::parse(data.into())?;
9+
_ = black_box(url.user());
10+
_ = black_box(url.password());
11+
_ = black_box(url.password());
12+
if let Some(safe_host) = black_box(url.host_argument_safe()) {
13+
// Ensure malicious host paths can't be returned see;
14+
// https://secure.phabricator.com/T12961
15+
assert!(!safe_host.starts_with("ssh://-"));
16+
}
17+
_ = black_box(url.path_argument_safe());
18+
_ = black_box(url.path_is_root());
19+
_ = black_box(url.port_or_default());
20+
_ = black_box(url.canonicalized(Path::new("/cwd")));
21+
_ = black_box(url.to_bstring());
22+
23+
_ = black_box(gix_url::expand_path::parse(data.into()));
24+
Ok(())
25+
}
326

427
fuzz_target!(|data: &[u8]| {
5-
let _a = gix_url::parse(data.into());
28+
_ = black_box(fuzz(data));
629
});

0 commit comments

Comments
 (0)