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

Fuzzing: Add more fuzzers #7622

Merged
merged 1 commit into from
Mar 5, 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
4 changes: 3 additions & 1 deletion go/test/fuzzing/oss_fuzz_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
# limitations under the License.

compile_go_fuzzer ./go/test/fuzzing Fuzz vtctl_fuzzer
compile_go_fuzzer ./go/vt/sqlparser Fuzz fuzz
compile_go_fuzzer ./go/test/fuzzing FuzzIsDML is_dml_fuzzer
compile_go_fuzzer ./go/test/fuzzing FuzzNormalizer normalizer_fuzzer
compile_go_fuzzer ./go/test/fuzzing FuzzParser parser_fuzzer


# Build dictionaries
Expand Down
30 changes: 26 additions & 4 deletions go/vt/sqlparser/fuzz.go → go/test/fuzzing/parser_fuzzer.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Vitess Authors.
Copyright 2021 The Vitess Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -13,11 +13,33 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// +build gofuzz

package sqlparser
package fuzzing

func Fuzz(data []byte) int {
_, err := Parse(string(data))
import (
querypb "vitess.io/vitess/go/vt/proto/query"
"vitess.io/vitess/go/vt/sqlparser"
)

func FuzzIsDML(data []byte) int {
_ = sqlparser.IsDML(string(data))
return 1
}

func FuzzNormalizer(data []byte) int {
stmt, err := sqlparser.Parse(string(data))
if err != nil {
return -1
}
prefix := "bv"
bv := make(map[string]*querypb.BindVariable)
sqlparser.Normalize(stmt, bv, prefix)
return 1
}

func FuzzParser(data []byte) int {
_, err := sqlparser.Parse(string(data))
if err != nil {
return 0
}
Expand Down