Add fuzzing (#36)

* Add fuzzing

Fuzzing can be useful to find crashes on random input.
Running this for a short while should already result in a crash, proving
it's usefulness.
This commit is contained in:
Midas Lambrichts 2020-08-20 14:52:42 +02:00 committed by GitHub
parent f9c163e557
commit d240151f8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 71 additions and 0 deletions

3
fuzz/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
target
corpus
artifacts

26
fuzz/Cargo.toml Normal file
View File

@ -0,0 +1,26 @@
[package]
authors = ["Automatically generated"]
edition = "2018"
name = "grass-fuzz"
publish = false
version = "0.0.0"
[package.metadata]
cargo-fuzz = true
[dependencies]
libfuzzer-sys = "0.3"
[dependencies.grass]
path = ".."
# Prevent this from interfering with workspaces
[workspace]
members = ["."]
[[bin]]
doc = false
name = "from_string_parsing"
path = "fuzz_targets/from_string_parsing.rs"
test = false

28
fuzz/README.md Normal file
View File

@ -0,0 +1,28 @@
# Fuzz
Fuzzing targets for the grass library.
## Installing
You'll need `cargo-fuzz` for this to work, simply do:
```
cargo install cargo-fuzz
```
## Running
Get a list of available targets with:
```
cargo fuzz list
```
And run a available target simply with:
```
cargo fuzz run <target>
```
You might have to use nightly:
```
cargo +nightly fuzz run <target>
```
## More info about fuzzing
Consult the [fuzzing book](https://rust-fuzz.github.io/book/introduction.html).

View File

@ -0,0 +1,14 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
fuzz_target!(|data: &[u8]| {
if let Ok(s) = std::str::from_utf8(data) {
let options = grass::Options::default();
let _ = grass::from_string(
s.to_owned(),
&options
);
}
});