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

mysql: Small adjustments to fuzzer #7907

Merged
merged 1 commit into from
Apr 21, 2021
Merged
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
25 changes: 15 additions & 10 deletions go/mysql/mysql_fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (

"vitess.io/vitess/go/sqltypes"
querypb "vitess.io/vitess/go/vt/proto/query"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/tlstest"
"vitess.io/vitess/go/vt/vttls"
)
Expand Down Expand Up @@ -302,23 +301,29 @@ func (th *fuzzTestHandler) WarningCount(c *Conn) uint16 {
return th.warnings
}

func (c *Conn) writeFuzzedPacket(packet []byte) {
c.sequence = 0
data, pos := c.startEphemeralPacketWithHeader(len(packet) + 1)
copy(data[pos:], packet)
_ = c.writeEphemeralPacket()
}

func FuzzTLSServer(data []byte) int {
if len(data) < 40 {
return -1
}
// totalQueries is the number of queries the fuzzer
// makes in each fuzz iteration
totalQueries := 20
var queries []string
var queries [][]byte
c := gofuzzheaders.NewConsumer(data)
for i := 0; i < totalQueries; i++ {
query, err := c.GetString()
query, err := c.GetBytes()
if err != nil {
return -1
}

// We parse each query now to exit if the queries
// are invalid
_, err = sqlparser.Parse(query)
if err != nil {
return -1
if len(query) < 40 {
continue
}
queries = append(queries, query)
}
Expand Down Expand Up @@ -379,7 +384,7 @@ func FuzzTLSServer(data []byte) int {
}

for i := 0; i < len(queries); i++ {
_, _ = conn.ExecuteFetch(queries[i], 1000, true)
conn.writeFuzzedPacket(queries[i])
}
return 1
}