Skip to content
This repository was archived by the owner on Nov 14, 2022. It is now read-only.

Commit 2d04266

Browse files
authored
Merge pull request apache#312 from PsiACE/main
Add fuzzer based on honggfuzz
2 parents 5bc109a + a12dd0e commit 2d04266

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

docs/fuzzing.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Fuzzing
2+
3+
## Installing `honggfuzz`
4+
5+
```
6+
cargo install honggfuzz
7+
```
8+
9+
Install [dependencies](https://github.com/rust-fuzz/honggfuzz-rs#dependencies) for your system.
10+
11+
## Running the fuzzer
12+
13+
Running the fuzzer is as easy as running in the `fuzz` directory.
14+
15+
Choose a target:
16+
17+
These are `[[bin]]` entries in `Cargo.toml`.
18+
List them with `cargo read-manifest | jq '.targets[].name'` from the `fuzz` directory.
19+
20+
Run the fuzzer:
21+
22+
```shell
23+
cd fuzz
24+
cargo hfuzz run <target>
25+
```
26+
27+
After a panic is found, get a stack trace with:
28+
29+
```shell
30+
cargo hfuzz run-debug <target> hfuzz_workspace/<target>/*.fuzz
31+
```
32+
33+
For example, with the `fuzz_parse_sql` target:
34+
35+
```shell
36+
cargo hfuzz run fuzz_parse_sql
37+
cargo hfuzz run-debug fuzz_parse_sql hfuzz_workspace/fuzz_parse_sql/*.fuzz
38+
```

fuzz/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
corpus
2+
hfuzz_target
3+
hfuzz_workspace

fuzz/Cargo.toml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "fuzz"
3+
version = "0.1.0"
4+
edition = "2018"
5+
publish = false
6+
7+
[dependencies]
8+
honggfuzz = "0.5.54"
9+
sqlparser = { path = ".." }
10+
11+
# Prevent this from interfering with workspaces
12+
[workspace]
13+
members = ["."]
14+
15+
[[bin]]
16+
name = "fuzz_parse_sql"
17+
path = "fuzz_targets/fuzz_parse_sql.rs"

fuzz/fuzz_targets/fuzz_parse_sql.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use honggfuzz::fuzz;
2+
use sqlparser::dialect::GenericDialect;
3+
use sqlparser::parser::Parser;
4+
5+
fn main() {
6+
loop {
7+
fuzz!(|data: String| {
8+
let dialect = GenericDialect {};
9+
let _ = Parser::parse_sql(&dialect, &data);
10+
});
11+
}
12+
}

0 commit comments

Comments
 (0)