Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fuzz: hook up honggfuzz to a few targets #5519

Merged
merged 1 commit into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fuzz: hook up honggfuzz to a few targets
  • Loading branch information
maddyblue committed Jan 30, 2021
commit 5eb09adb687c4980fc899582cefaa5e43d6e8ce7
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"demo/billing",
"fuzz",
"play/mbta",
"src/avro",
"src/avro-derive",
Expand Down
3 changes: 3 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
corpus
hfuzz_target
hfuzz_workspace
18 changes: 18 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "fuzz"
version = "0.0.1"
publish = false
edition = "2018"

[dependencies]
honggfuzz = "0.5"
repr = { path = "../src/repr" }
sql-parser = { path = "../src/sql-parser" }

[[bin]]
name = "fuzz_parse_statements"
path = "fuzz_targets/fuzz_parse_statements.rs"

[[bin]]
name = "fuzz_parse_time"
path = "fuzz_targets/fuzz_parse_time.rs"
35 changes: 35 additions & 0 deletions fuzz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# fuzz

## Installing `honggfuzz`

```
cargo install honggfuzz
```

Install [dependencies](https://github.com/rust-fuzz/honggfuzz-rs#dependencies) for your system.

## Fuzzing

Choose a target.
These are `[[bin]]` entries in `Cargo.toml`.
List them with `cargo read-manifest | jq '.targets[].name'` from the `fuzz` directory.

Run the fuzzer:

```shell
cd fuzz
cargo hfuzz run <target>
```

After a panic is found, get a stack trace with:

```shell
cargo hfuzz run-debug <target> hfuzz_workspace/<target>/*.fuzz
```

For example, with the `fuzz_parse_time` target:

```shell
cargo hfuzz run fuzz_parse_time
cargo hfuzz run-debug fuzz_parse_time hfuzz_workspace/fuzz_parse_time/*.fuzz
```
19 changes: 19 additions & 0 deletions fuzz/fuzz_targets/fuzz_parse_statements.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright Materialize, Inc. All rights reserved.
//
// Use of this software is governed by the Business Source License
// included in the LICENSE file.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

use honggfuzz::fuzz;
use sql_parser::parser::parse_statements;

fn main() {
loop {
fuzz!(|data: String| {
let _ = parse_statements(&data);
});
}
}
19 changes: 19 additions & 0 deletions fuzz/fuzz_targets/fuzz_parse_time.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright Materialize, Inc. All rights reserved.
//
// Use of this software is governed by the Business Source License
// included in the LICENSE file.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

use honggfuzz::fuzz;
use repr::strconv::parse_time;

fn main() {
loop {
fuzz!(|data: String| {
let _ = parse_time(&data);
});
}
}
11 changes: 11 additions & 0 deletions fuzzbuzz.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright Materialize, Inc. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.

base:
language: rust