Skip to content

Commit

Permalink
add a fuzzing target for the parser
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Nov 1, 2021
1 parent 9d06072 commit 4b30c32
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
3 changes: 3 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target
corpus
artifacts
25 changes: 25 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions fuzz/corpus/fuzz_target_parse/guid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{6d93bade-bd9f-4e13-8914-9474e1e3567b}
1 change: 1 addition & 0 deletions fuzz/corpus/fuzz_target_parse/hyphenated
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
67e55044-10b1-426f-9247-bb680e5fe0c8
1 change: 1 addition & 0 deletions fuzz/corpus/fuzz_target_parse/simple
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
67e5504410b1426f9247bb680e5fe0c8
1 change: 1 addition & 0 deletions fuzz/corpus/fuzz_target_parse/urn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
urn:uuid:67e55044-10b1-426f-9247-bb680e5fe0c8
12 changes: 12 additions & 0 deletions fuzz/fuzz_targets/fuzz_target_parse.rs
Original file line number Diff line number Diff line change
@@ -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);
}
});

0 comments on commit 4b30c32

Please sign in to comment.