Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
Signed-off-by: AdamKorcz <[email protected]>
  • Loading branch information
AdamKorcz committed Apr 20, 2021
1 parent a246ffa commit 8ef0b4a
Showing 1 changed file with 15 additions and 10 deletions.
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
}

0 comments on commit 8ef0b4a

Please sign in to comment.