test: fuzz bounded protocol parsers
This commit is contained in:
@@ -95,3 +95,18 @@ func TestJSONRPCRejectsOversizeAndMalformedRequests_BH_CTL_16(t *testing.T) {
|
||||
t.Fatalf("malformed response = %s", malformedBody)
|
||||
}
|
||||
}
|
||||
|
||||
func FuzzDecodeJSONRPCRequestBounded_SEC_CTL_01(f *testing.F) {
|
||||
f.Add([]byte(`{"jsonrpc":"2.0","id":1,"method":"listClients","params":{}}`))
|
||||
f.Add([]byte(`{"jsonrpc":"2.0","id":null,"method":"listClients"}`))
|
||||
f.Add([]byte(`{"jsonrpc":"2.0","id":1,"method":"listClients"}{}`))
|
||||
f.Fuzz(func(t *testing.T, body []byte) {
|
||||
// Keep fuzzing at the same independently enforced boundary as the
|
||||
// production handler rather than allowing a corpus entry to allocate
|
||||
// unbounded JSON decoder state.
|
||||
if len(body) > 64<<10 {
|
||||
return
|
||||
}
|
||||
_, _, _ = decodeJSONRPCRequest(body, 64<<10)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user