From 4b30c32ca8fa841769188873fb76c432b4a450b6 Mon Sep 17 00:00:00 2001 From: KodrAus Date: Tue, 2 Nov 2021 09:46:18 +1000 Subject: [PATCH] add a fuzzing target for the parser --- CONTRIBUTING.md | 5 +++++ fuzz/.gitignore | 3 +++ fuzz/Cargo.toml | 25 ++++++++++++++++++++++++ fuzz/corpus/fuzz_target_parse/guid | 1 + fuzz/corpus/fuzz_target_parse/hyphenated | 1 + fuzz/corpus/fuzz_target_parse/simple | 1 + fuzz/corpus/fuzz_target_parse/urn | 1 + fuzz/fuzz_targets/fuzz_target_parse.rs | 12 ++++++++++++ 8 files changed, 49 insertions(+) create mode 100644 fuzz/.gitignore create mode 100644 fuzz/Cargo.toml create mode 100644 fuzz/corpus/fuzz_target_parse/guid create mode 100644 fuzz/corpus/fuzz_target_parse/hyphenated create mode 100644 fuzz/corpus/fuzz_target_parse/simple create mode 100644 fuzz/corpus/fuzz_target_parse/urn create mode 100644 fuzz/fuzz_targets/fuzz_target_parse.rs diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 087f23d8..1025171a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -118,6 +118,10 @@ You can follow [this link][lrus] to look for issues like this. [lrus]: https://github.com/uuid-rs/uuid/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc +# Fuzzing +We use [`cargo fuzz`] to fuzz test various parts of `uuid`. See their guide +for more details on what fuzzing is and how to run the tests yourself. + # Helpful Links [Helpful Links]: #helpful-links @@ -133,3 +137,4 @@ seasoned developers, some useful places to look for information are: [u-r-l-o]: https://users.rust-lang.org [Discussions]: https://github.com/uuid-rs/uuid/discussions [search existing issues]: https://github.com/uuid-rs/uuid/search?q=&type=Issues&utf8=%E2%9C%93 +[`cargo fuzz`]: https://rust-fuzz.github.io/book/cargo-fuzz.html diff --git a/fuzz/.gitignore b/fuzz/.gitignore new file mode 100644 index 00000000..a0925114 --- /dev/null +++ b/fuzz/.gitignore @@ -0,0 +1,3 @@ +target +corpus +artifacts diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 00000000..6636d848 --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "uuid-fuzz" +version = "0.0.0" +authors = ["Automatically generated"] +publish = false +edition = "2018" + +[package.metadata] +cargo-fuzz = true + +[dependencies] +libfuzzer-sys = "0.4" + +[dependencies.uuid] +path = ".." + +# Prevent this from interfering with workspaces +[workspace] +members = ["."] + +[[bin]] +name = "fuzz_target_parse" +path = "fuzz_targets/fuzz_target_parse.rs" +test = false +doc = false diff --git a/fuzz/corpus/fuzz_target_parse/guid b/fuzz/corpus/fuzz_target_parse/guid new file mode 100644 index 00000000..52f9035e --- /dev/null +++ b/fuzz/corpus/fuzz_target_parse/guid @@ -0,0 +1 @@ +{6d93bade-bd9f-4e13-8914-9474e1e3567b} \ No newline at end of file diff --git a/fuzz/corpus/fuzz_target_parse/hyphenated b/fuzz/corpus/fuzz_target_parse/hyphenated new file mode 100644 index 00000000..e135d7f6 --- /dev/null +++ b/fuzz/corpus/fuzz_target_parse/hyphenated @@ -0,0 +1 @@ +67e55044-10b1-426f-9247-bb680e5fe0c8 \ No newline at end of file diff --git a/fuzz/corpus/fuzz_target_parse/simple b/fuzz/corpus/fuzz_target_parse/simple new file mode 100644 index 00000000..d022f25a --- /dev/null +++ b/fuzz/corpus/fuzz_target_parse/simple @@ -0,0 +1 @@ +67e5504410b1426f9247bb680e5fe0c8 \ No newline at end of file diff --git a/fuzz/corpus/fuzz_target_parse/urn b/fuzz/corpus/fuzz_target_parse/urn new file mode 100644 index 00000000..efc17cfc --- /dev/null +++ b/fuzz/corpus/fuzz_target_parse/urn @@ -0,0 +1 @@ +urn:uuid:67e55044-10b1-426f-9247-bb680e5fe0c8 \ No newline at end of file diff --git a/fuzz/fuzz_targets/fuzz_target_parse.rs b/fuzz/fuzz_targets/fuzz_target_parse.rs new file mode 100644 index 00000000..f6650498 --- /dev/null +++ b/fuzz/fuzz_targets/fuzz_target_parse.rs @@ -0,0 +1,12 @@ +#![no_main] +use libfuzzer_sys::fuzz_target; + +use std::str; +use uuid::Uuid; + +fuzz_target!(|data: &[u8]| { + if let Ok(uuid) = str::from_utf8(data) { + // Ensure the parser doesn't panic + let _ = Uuid::parse_str(uuid); + } +});