wtwire: explain emptyMsg parameter in function comment

This makes it unnecessary to explain the argument at every call site, so
we can simplify each fuzz target.
This commit is contained in:
Matt Morehouse 2024-11-13 15:50:11 -06:00
parent 567ff5d751
commit 9dd921243d
No known key found for this signature in database
GPG Key ID: CC8ECA224831C982

View File

@ -21,7 +21,9 @@ func prefixWithMsgType(data []byte, prefix MessageType) []byte {
// wireMsgHarness performs the actual fuzz testing of the appropriate wire // wireMsgHarness performs the actual fuzz testing of the appropriate wire
// message. This function will check that the passed-in message passes wire // message. This function will check that the passed-in message passes wire
// length checks, is a valid message once deserialized, and passes a sequence of // length checks, is a valid message once deserialized, and passes a sequence of
// serialization and deserialization checks. // serialization and deserialization checks. emptyMsg must be an empty Message
// of the type to be fuzzed, as it is used to determine the appropriate prefix
// bytes and max payload length for decoding.
func wireMsgHarness(t *testing.T, data []byte, emptyMsg Message) { func wireMsgHarness(t *testing.T, data []byte, emptyMsg Message) {
t.Helper() t.Helper()
@ -58,80 +60,48 @@ func wireMsgHarness(t *testing.T, data []byte, emptyMsg Message) {
func FuzzCreateSessionReply(f *testing.F) { func FuzzCreateSessionReply(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
// Create an empty message so that the FuzzHarness func can wireMsgHarness(t, data, &CreateSessionReply{})
// check if the max payload constraint is violated.
emptyMsg := CreateSessionReply{}
wireMsgHarness(t, data, &emptyMsg)
}) })
} }
func FuzzCreateSession(f *testing.F) { func FuzzCreateSession(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
// Create an empty message so that the FuzzHarness func can wireMsgHarness(t, data, &CreateSession{})
// check if the max payload constraint is violated.
emptyMsg := CreateSession{}
wireMsgHarness(t, data, &emptyMsg)
}) })
} }
func FuzzDeleteSessionReply(f *testing.F) { func FuzzDeleteSessionReply(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
// Create an empty message so that the FuzzHarness func can wireMsgHarness(t, data, &DeleteSessionReply{})
// check if the max payload constraint is violated.
emptyMsg := DeleteSessionReply{}
wireMsgHarness(t, data, &emptyMsg)
}) })
} }
func FuzzDeleteSession(f *testing.F) { func FuzzDeleteSession(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
// Create an empty message so that the FuzzHarness func can wireMsgHarness(t, data, &DeleteSession{})
// check if the max payload constraint is violated.
emptyMsg := DeleteSession{}
wireMsgHarness(t, data, &emptyMsg)
}) })
} }
func FuzzError(f *testing.F) { func FuzzError(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
// Create an empty message so that the FuzzHarness func can wireMsgHarness(t, data, &Error{})
// check if the max payload constraint is violated.
emptyMsg := Error{}
wireMsgHarness(t, data, &emptyMsg)
}) })
} }
func FuzzInit(f *testing.F) { func FuzzInit(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
// Create an empty message so that the FuzzHarness func can wireMsgHarness(t, data, &Init{})
// check if the max payload constraint is violated.
emptyMsg := Init{}
wireMsgHarness(t, data, &emptyMsg)
}) })
} }
func FuzzStateUpdateReply(f *testing.F) { func FuzzStateUpdateReply(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
// Create an empty message so that the FuzzHarness func can wireMsgHarness(t, data, &StateUpdateReply{})
// check if the max payload constraint is violated.
emptyMsg := StateUpdateReply{}
wireMsgHarness(t, data, &emptyMsg)
}) })
} }
func FuzzStateUpdate(f *testing.F) { func FuzzStateUpdate(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
// Create an empty message so that the FuzzHarness func can wireMsgHarness(t, data, &StateUpdate{})
// check if the max payload constraint is violated.
emptyMsg := StateUpdate{}
wireMsgHarness(t, data, &emptyMsg)
}) })
} }