Skip to content

Commit 1e65984

Browse files
committed
test: add fuzzer
Signed-off-by: Chojan Shang <[email protected]>
1 parent 35ef0ee commit 1e65984

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

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/README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# fuzz
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+
## Fuzzing
12+
13+
Choose a target.
14+
These are `[[bin]]` entries in `Cargo.toml`.
15+
List them with `cargo read-manifest | jq '.targets[].name'` from the `fuzz` directory.
16+
17+
Run the fuzzer:
18+
19+
```shell
20+
cd fuzz
21+
cargo hfuzz run <target>
22+
```
23+
24+
After a panic is found, get a stack trace with:
25+
26+
```shell
27+
cargo hfuzz run-debug <target> hfuzz_workspace/<target>/*.fuzz
28+
```
29+
30+
For example, with the `fuzz_parse_sql` target:
31+
32+
```shell
33+
cargo hfuzz run fuzz_parse_sql
34+
cargo hfuzz run-debug fuzz_parse_sql hfuzz_workspace/fuzz_parse_sql/*.fuzz
35+
```

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)