-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9114 from AdamKorcz/fuzz24
Fuzzing: Add new and modify existing
- Loading branch information
Showing
9 changed files
with
1,369 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//go:build gofuzz | ||
// +build gofuzz | ||
|
||
/* | ||
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. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
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. | ||
*/ | ||
|
||
package fuzzing | ||
|
||
import ( | ||
"vitess.io/vitess/go/vt/sqlparser" | ||
) | ||
|
||
// FuzzEqualsSQLNode implements the fuzzer | ||
func FuzzEqualsSQLNode(data []byte) int { | ||
if len(data) < 10 { | ||
return 0 | ||
} | ||
if (len(data) % 2) != 0 { | ||
return 0 | ||
} | ||
firstHalf := string(data[:len(data)/2]) | ||
secondHalf := string(data[(len(data)/2)+1:]) | ||
inA, err := sqlparser.Parse(firstHalf) | ||
if err != nil { | ||
return 0 | ||
} | ||
inB, err := sqlparser.Parse(secondHalf) | ||
if err != nil { | ||
return 0 | ||
} | ||
|
||
// There are 3 targets in this fuzzer: | ||
// 1) sqlparser.EqualsSQLNode | ||
// 2) sqlparser.CloneSQLNode | ||
// 3) sqlparser.VisitSQLNode | ||
|
||
// Target 1: | ||
_ = sqlparser.EqualsSQLNode(inA, inB) | ||
|
||
// Target 2: | ||
newSQLNode := sqlparser.CloneSQLNode(inA) | ||
if !sqlparser.EqualsSQLNode(inA, newSQLNode) { | ||
panic("These two nodes should be identical") | ||
} | ||
|
||
// Target 3: | ||
_ = sqlparser.VisitSQLNode(inA, func(node sqlparser.SQLNode) (bool, error) { return false, nil }) | ||
return 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
//go:build gofuzz | ||
// +build gofuzz | ||
|
||
/* | ||
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. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
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. | ||
*/ | ||
|
||
package fuzzing | ||
|
||
import ( | ||
fuzz "github.com/AdaLogics/go-fuzz-headers" | ||
|
||
"vitess.io/vitess/go/vt/schema" | ||
"vitess.io/vitess/go/vt/sqlparser" | ||
) | ||
|
||
// FuzzOnlineDDLFromCommentedStatement implements a fuzzer | ||
// that targets schema.OnlineDDLFromCommentedStatement | ||
func FuzzOnlineDDLFromCommentedStatement(data []byte) int { | ||
stmt, err := sqlparser.Parse(string(data)) | ||
if err != nil { | ||
return 0 | ||
} | ||
onlineDDL, err := schema.OnlineDDLFromCommentedStatement(stmt) | ||
if err != nil { | ||
return 0 | ||
} | ||
_, _ = onlineDDL.GetAction() | ||
_, _, _ = onlineDDL.GetActionStr() | ||
_ = onlineDDL.GetGCUUID() | ||
return 1 | ||
} | ||
|
||
// FuzzNewOnlineDDLs implements a fuzzer that | ||
// targets schema.NewOnlineDDLs | ||
func FuzzNewOnlineDDLs(data []byte) int { | ||
f := fuzz.NewConsumer(data) | ||
|
||
keyspace, err := f.GetString() | ||
if err != nil { | ||
return 0 | ||
} | ||
|
||
ddlstmtString, err := f.GetString() | ||
if err != nil { | ||
return 0 | ||
} | ||
ddlStmt, _, err := schema.ParseOnlineDDLStatement(ddlstmtString) | ||
if err != nil { | ||
return 0 | ||
} | ||
|
||
sql, err := f.GetString() | ||
if err != nil { | ||
return 0 | ||
} | ||
|
||
ddlStrategySetting := &schema.DDLStrategySetting{} | ||
err = f.GenerateStruct(ddlStrategySetting) | ||
if err != nil { | ||
return 0 | ||
} | ||
|
||
requestContext, err := f.GetString() | ||
if err != nil { | ||
return 0 | ||
} | ||
|
||
onlineDDLs, err := schema.NewOnlineDDLs(keyspace, sql, ddlStmt, ddlStrategySetting, requestContext) | ||
if err != nil { | ||
return 0 | ||
} | ||
for _, onlineDDL := range onlineDDLs { | ||
_, _ = onlineDDL.GetAction() | ||
_, _, _ = onlineDDL.GetActionStr() | ||
_ = onlineDDL.GetGCUUID() | ||
} | ||
return 1 | ||
} |
Oops, something went wrong.