Skip to content

Add fuzzer based on cargo-fuzz #211

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

Closed
wants to merge 5 commits into from
Closed
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
9 changes: 9 additions & 0 deletions docs/fuzzing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Fuzzing

sqlparser uses the tool `cargo-fuzz`. This tool can be installed using: `cargo install cargo-fuzz`.
Cargo-fuzz also requires nightly to be installed: `rustup install nightly`

Running the fuzzer is as easy as running in the `fuzz` directory:

`cargo +nightly fuzz run parse_sql -- -max_len=64 -jobs=16 -timeout=1`

4 changes: 4 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

target
corpus
artifacts
26 changes: 26 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

[package]
name = "sqlparser-fuzz"
version = "0.0.0"
authors = ["Automatically generated"]
publish = false
edition = "2018"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.3"

[dependencies.sqlparser]
path = ".."

# Prevent this from interfering with workspaces
[workspace]
members = ["."]

[[bin]]
name = "parse_sql"
path = "fuzz_targets/parse_sql.rs"
test = false
doc = false
10 changes: 10 additions & 0 deletions fuzz/fuzz_targets/parse_sql.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
use sqlparser::dialect::GenericDialect;
use sqlparser::parser::Parser;

fuzz_target!(|data: String| {
let dialect = GenericDialect {};

let _ = Parser::parse_sql(&dialect, &data);
});