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:
parent
f9c163e557
commit
d240151f8c
3
fuzz/.gitignore
vendored
Normal file
3
fuzz/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
target
|
||||||
|
corpus
|
||||||
|
artifacts
|
26
fuzz/Cargo.toml
Normal file
26
fuzz/Cargo.toml
Normal 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
28
fuzz/README.md
Normal 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).
|
14
fuzz/fuzz_targets/from_string_parsing.rs
Normal file
14
fuzz/fuzz_targets/from_string_parsing.rs
Normal 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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user