test/fuzz: add test to reproduce found fuzz errors

This commit is contained in:
William Banfield
2021-07-23 12:24:33 -04:00
parent 2abfe20114
commit cbdf0072fc
3 changed files with 56 additions and 4 deletions
+22 -4
View File
@@ -1,4 +1,4 @@
package handler
package server
import (
"bytes"
@@ -39,11 +39,29 @@ func Fuzz(data []byte) int {
if err := res.Body.Close(); err != nil {
panic(err)
}
if len(blob) > 0 {
recv := new(types.RPCResponse)
if err := json.Unmarshal(blob, recv); err != nil {
if len(blob) == 0 {
return 1
}
if inputJSONIsSlice(data) {
recv := []types.RPCResponse{}
if err := json.Unmarshal(blob, &recv); err != nil {
panic(err)
}
return 1
}
recv := &types.RPCResponse{}
if err := json.Unmarshal(blob, recv); err != nil {
panic(err)
}
return 1
}
func inputJSONIsSlice(input []byte) bool {
slice := []interface{}{}
err := json.Unmarshal(input, &slice)
if err != nil {
return false
}
return true
}