fuzz/lnwire: minor touch-ups, remove MaxPayloadLength

This commit makes the fuzz/lnwire tests build and run without
crashing.
This commit is contained in:
eugene 2021-07-14 11:17:08 -04:00
parent 07fa98fca5
commit 9cea8741b1
No known key found for this signature in database
GPG key ID: 118759E83439A9B1
31 changed files with 37 additions and 180 deletions

View file

@ -13,10 +13,6 @@ func Fuzz_accept_channel(data []byte) int {
// Prefix with MsgAcceptChannel. // Prefix with MsgAcceptChannel.
data = prefixWithMsgType(data, lnwire.MsgAcceptChannel) data = prefixWithMsgType(data, lnwire.MsgAcceptChannel)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.AcceptChannel{}
// We have to do this here instead of in fuzz.Harness so that // We have to do this here instead of in fuzz.Harness so that
// reflect.DeepEqual isn't called. Because of the UpfrontShutdownScript // reflect.DeepEqual isn't called. Because of the UpfrontShutdownScript
// encoding, the first message and second message aren't deeply equal since // encoding, the first message and second message aren't deeply equal since
@ -26,12 +22,9 @@ func Fuzz_accept_channel(data []byte) int {
r := bytes.NewReader(data) r := bytes.NewReader(data)
// Make sure byte array length (excluding 2 bytes for message type) is // Make sure byte array length (excluding 2 bytes for message type) is
// less than max payload size for the wire message. We check this because // less than max payload size for the wire message.
// otherwise `go-fuzz` will keep creating inputs that crash on ReadMessage
// due to a large message size.
payloadLen := uint32(len(data)) - 2 payloadLen := uint32(len(data)) - 2
if payloadLen > emptyMsg.MaxPayloadLength(0) { if payloadLen > lnwire.MaxMsgBody {
// Ignore this input - max payload constraint violated.
return 1 return 1
} }

View file

@ -11,10 +11,6 @@ func Fuzz_announce_signatures(data []byte) int {
// Prefix with MsgAnnounceSignatures. // Prefix with MsgAnnounceSignatures.
data = prefixWithMsgType(data, lnwire.MsgAnnounceSignatures) data = prefixWithMsgType(data, lnwire.MsgAnnounceSignatures)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.AnnounceSignatures{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_channel_announcement(data []byte) int {
// Prefix with MsgChannelAnnouncement. // Prefix with MsgChannelAnnouncement.
data = prefixWithMsgType(data, lnwire.MsgChannelAnnouncement) data = prefixWithMsgType(data, lnwire.MsgChannelAnnouncement)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.ChannelAnnouncement{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_channel_reestablish(data []byte) int {
// Prefix with MsgChannelReestablish. // Prefix with MsgChannelReestablish.
data = prefixWithMsgType(data, lnwire.MsgChannelReestablish) data = prefixWithMsgType(data, lnwire.MsgChannelReestablish)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.ChannelReestablish{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_channel_update(data []byte) int {
// Prefix with MsgChannelUpdate. // Prefix with MsgChannelUpdate.
data = prefixWithMsgType(data, lnwire.MsgChannelUpdate) data = prefixWithMsgType(data, lnwire.MsgChannelUpdate)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.ChannelUpdate{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_closing_signed(data []byte) int {
// Prefix with MsgClosingSigned. // Prefix with MsgClosingSigned.
data = prefixWithMsgType(data, lnwire.MsgClosingSigned) data = prefixWithMsgType(data, lnwire.MsgClosingSigned)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.ClosingSigned{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_commit_sig(data []byte) int {
// Prefix with MsgCommitSig. // Prefix with MsgCommitSig.
data = prefixWithMsgType(data, lnwire.MsgCommitSig) data = prefixWithMsgType(data, lnwire.MsgCommitSig)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.CommitSig{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_error(data []byte) int {
// Prefix with MsgError. // Prefix with MsgError.
data = prefixWithMsgType(data, lnwire.MsgError) data = prefixWithMsgType(data, lnwire.MsgError)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.Error{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_funding_created(data []byte) int {
// Prefix with MsgFundingCreated. // Prefix with MsgFundingCreated.
data = prefixWithMsgType(data, lnwire.MsgFundingCreated) data = prefixWithMsgType(data, lnwire.MsgFundingCreated)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.FundingCreated{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_funding_locked(data []byte) int {
// Prefix with MsgFundingLocked. // Prefix with MsgFundingLocked.
data = prefixWithMsgType(data, lnwire.MsgFundingLocked) data = prefixWithMsgType(data, lnwire.MsgFundingLocked)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.FundingLocked{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_funding_signed(data []byte) int {
// Prefix with MsgFundingSigned. // Prefix with MsgFundingSigned.
prefixWithMsgType(data, lnwire.MsgFundingSigned) prefixWithMsgType(data, lnwire.MsgFundingSigned)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.FundingSigned{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -24,25 +24,18 @@ func prefixWithMsgType(data []byte, prefix lnwire.MessageType) []byte {
// is a valid message once deserialized, and passes a sequence of serialization // is a valid message once deserialized, and passes a sequence of serialization
// and deserialization checks. Returns an int that determines whether the input // and deserialization checks. Returns an int that determines whether the input
// is unique or not. // is unique or not.
func harness(data []byte, emptyMsg lnwire.Message) int { func harness(data []byte) int {
// Create a reader with the byte array. // Create a reader with the byte array.
r := bytes.NewReader(data) r := bytes.NewReader(data)
// Make sure byte array length (excluding 2 bytes for message type) is // Check that the created message is not greater than the maximum
// less than max payload size for the wire message. We check this because // message size.
// otherwise `go-fuzz` will keep creating inputs that crash on ReadMessage if len(data) > lnwire.MaxSliceLength {
// due to a large message size.
payloadLen := uint32(len(data)) - 2
if payloadLen > emptyMsg.MaxPayloadLength(0) {
// Ignore this input - max payload constraint violated.
return 1 return 1
} }
msg, err := lnwire.ReadMessage(r, 0) msg, err := lnwire.ReadMessage(r, 0)
if err != nil { if err != nil {
// go-fuzz generated []byte that cannot be represented as a
// wire message but we will return 0 so go-fuzz can modify the
// input.
return 1 return 1
} }
@ -67,6 +60,5 @@ func harness(data []byte, emptyMsg lnwire.Message) int {
panic("original message and deserialized message are not deeply equal") panic("original message and deserialized message are not deeply equal")
} }
// Add this input to the corpus.
return 1 return 1
} }

View file

@ -11,10 +11,6 @@ func Fuzz_gossip_timestamp_range(data []byte) int {
// Prefix with MsgGossipTimestampRange. // Prefix with MsgGossipTimestampRange.
data = prefixWithMsgType(data, lnwire.MsgGossipTimestampRange) data = prefixWithMsgType(data, lnwire.MsgGossipTimestampRange)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.GossipTimestampRange{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_init(data []byte) int {
// Prefix with MsgInit. // Prefix with MsgInit.
data = prefixWithMsgType(data, lnwire.MsgInit) data = prefixWithMsgType(data, lnwire.MsgInit)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.Init{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -14,10 +14,6 @@ func Fuzz_node_announcement(data []byte) int {
// Prefix with MsgNodeAnnouncement. // Prefix with MsgNodeAnnouncement.
data = prefixWithMsgType(data, lnwire.MsgNodeAnnouncement) data = prefixWithMsgType(data, lnwire.MsgNodeAnnouncement)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.NodeAnnouncement{}
// We have to do this here instead of in fuzz.Harness so that // We have to do this here instead of in fuzz.Harness so that
// reflect.DeepEqual isn't called. Address (de)serialization messes up // reflect.DeepEqual isn't called. Address (de)serialization messes up
// the fuzzing assertions. // the fuzzing assertions.
@ -26,20 +22,14 @@ func Fuzz_node_announcement(data []byte) int {
r := bytes.NewReader(data) r := bytes.NewReader(data)
// Make sure byte array length (excluding 2 bytes for message type) is // Make sure byte array length (excluding 2 bytes for message type) is
// less than max payload size for the wire message. We check this because // less than max payload size for the wire message.
// otherwise `go-fuzz` will keep creating inputs that crash on ReadMessage
// due to a large message size.
payloadLen := uint32(len(data)) - 2 payloadLen := uint32(len(data)) - 2
if payloadLen > emptyMsg.MaxPayloadLength(0) { if payloadLen > lnwire.MaxMsgBody {
// Ignore this input - max payload constraint violated.
return 1 return 1
} }
msg, err := lnwire.ReadMessage(r, 0) msg, err := lnwire.ReadMessage(r, 0)
if err != nil { if err != nil {
// go-fuzz generated []byte that cannot be represented as a
// wire message but we will return 0 so go-fuzz can modify the
// input.
return 1 return 1
} }

View file

@ -13,10 +13,6 @@ func Fuzz_open_channel(data []byte) int {
// Prefix with MsgOpenChannel. // Prefix with MsgOpenChannel.
data = prefixWithMsgType(data, lnwire.MsgOpenChannel) data = prefixWithMsgType(data, lnwire.MsgOpenChannel)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.OpenChannel{}
// We have to do this here instead of in fuzz.Harness so that // We have to do this here instead of in fuzz.Harness so that
// reflect.DeepEqual isn't called. Because of the UpfrontShutdownScript // reflect.DeepEqual isn't called. Because of the UpfrontShutdownScript
// encoding, the first message and second message aren't deeply equal since // encoding, the first message and second message aren't deeply equal since
@ -26,20 +22,14 @@ func Fuzz_open_channel(data []byte) int {
r := bytes.NewReader(data) r := bytes.NewReader(data)
// Make sure byte array length (excluding 2 bytes for message type) is // Make sure byte array length (excluding 2 bytes for message type) is
// less than max payload size for the wire message. We check this because // less than max payload size for the wire message.
// otherwise `go-fuzz` will keep creating inputs that crash on ReadMessage
// due to a large message size.
payloadLen := uint32(len(data)) - 2 payloadLen := uint32(len(data)) - 2
if payloadLen > emptyMsg.MaxPayloadLength(0) { if payloadLen > lnwire.MaxMsgBody {
// Ignore this input - max payload constraint violated.
return 1 return 1
} }
msg, err := lnwire.ReadMessage(r, 0) msg, err := lnwire.ReadMessage(r, 0)
if err != nil { if err != nil {
// go-fuzz generated []byte that cannot be represented as a
// wire message but we will return 0 so go-fuzz can modify the
// input.
return 1 return 1
} }

View file

@ -11,10 +11,6 @@ func Fuzz_ping(data []byte) int {
// Prefix with MsgPing. // Prefix with MsgPing.
data = prefixWithMsgType(data, lnwire.MsgPing) data = prefixWithMsgType(data, lnwire.MsgPing)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.Ping{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_pong(data []byte) int {
// Prefix with MsgPong. // Prefix with MsgPong.
data = prefixWithMsgType(data, lnwire.MsgPong) data = prefixWithMsgType(data, lnwire.MsgPong)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.Pong{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_query_channel_range(data []byte) int {
// Prefix with MsgQueryChannelRange. // Prefix with MsgQueryChannelRange.
data = prefixWithMsgType(data, lnwire.MsgQueryChannelRange) data = prefixWithMsgType(data, lnwire.MsgQueryChannelRange)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.QueryChannelRange{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_query_short_chan_ids(data []byte) int {
// Prefix with MsgQueryShortChanIDs. // Prefix with MsgQueryShortChanIDs.
data = prefixWithMsgType(data, lnwire.MsgQueryShortChanIDs) data = prefixWithMsgType(data, lnwire.MsgQueryShortChanIDs)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.QueryShortChanIDs{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -42,10 +42,6 @@ func Fuzz_query_short_chan_ids_zlib(data []byte) int {
// Prefix with MsgQueryShortChanIDs. // Prefix with MsgQueryShortChanIDs.
payload = prefixWithMsgType(payload, lnwire.MsgQueryShortChanIDs) payload = prefixWithMsgType(payload, lnwire.MsgQueryShortChanIDs)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.QueryShortChanIDs{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(payload, &emptyMsg) return harness(payload)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_reply_channel_range(data []byte) int {
// Prefix with MsgReplyChannelRange. // Prefix with MsgReplyChannelRange.
data = prefixWithMsgType(data, lnwire.MsgReplyChannelRange) data = prefixWithMsgType(data, lnwire.MsgReplyChannelRange)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.ReplyChannelRange{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -50,10 +50,6 @@ func Fuzz_reply_channel_range_zlib(data []byte) int {
// Prefix with MsgReplyChannelRange. // Prefix with MsgReplyChannelRange.
payload = prefixWithMsgType(payload, lnwire.MsgReplyChannelRange) payload = prefixWithMsgType(payload, lnwire.MsgReplyChannelRange)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.ReplyChannelRange{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(payload, &emptyMsg) return harness(payload)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_reply_short_chan_ids_end(data []byte) int {
// Prefix with MsgReplyShortChanIDsEnd. // Prefix with MsgReplyShortChanIDsEnd.
data = prefixWithMsgType(data, lnwire.MsgReplyShortChanIDsEnd) data = prefixWithMsgType(data, lnwire.MsgReplyShortChanIDsEnd)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.ReplyShortChanIDsEnd{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_revoke_and_ack(data []byte) int {
// Prefix with MsgRevokeAndAck. // Prefix with MsgRevokeAndAck.
data = prefixWithMsgType(data, lnwire.MsgRevokeAndAck) data = prefixWithMsgType(data, lnwire.MsgRevokeAndAck)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.RevokeAndAck{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_shutdown(data []byte) int {
// Prefix with MsgShutdown. // Prefix with MsgShutdown.
data = prefixWithMsgType(data, lnwire.MsgShutdown) data = prefixWithMsgType(data, lnwire.MsgShutdown)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.Shutdown{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_update_add_htlc(data []byte) int {
// Prefix with MsgUpdateAddHTLC. // Prefix with MsgUpdateAddHTLC.
data = prefixWithMsgType(data, lnwire.MsgUpdateAddHTLC) data = prefixWithMsgType(data, lnwire.MsgUpdateAddHTLC)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.UpdateAddHTLC{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_update_fail_htlc(data []byte) int {
// Prefix with MsgUpdateFailHTLC. // Prefix with MsgUpdateFailHTLC.
data = prefixWithMsgType(data, lnwire.MsgUpdateFailHTLC) data = prefixWithMsgType(data, lnwire.MsgUpdateFailHTLC)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.UpdateFailHTLC{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_update_fail_malformed_htlc(data []byte) int {
// Prefix with MsgUpdateFailMalformedHTLC. // Prefix with MsgUpdateFailMalformedHTLC.
data = prefixWithMsgType(data, lnwire.MsgUpdateFailMalformedHTLC) data = prefixWithMsgType(data, lnwire.MsgUpdateFailMalformedHTLC)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.UpdateFailMalformedHTLC{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_update_fee(data []byte) int {
// Prefix with MsgUpdateFee. // Prefix with MsgUpdateFee.
data = prefixWithMsgType(data, lnwire.MsgUpdateFee) data = prefixWithMsgType(data, lnwire.MsgUpdateFee)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.UpdateFee{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }

View file

@ -11,10 +11,6 @@ func Fuzz_update_fulfill_htlc(data []byte) int {
// Prefix with MsgUpdateFulfillHTLC. // Prefix with MsgUpdateFulfillHTLC.
data = prefixWithMsgType(data, lnwire.MsgUpdateFulfillHTLC) data = prefixWithMsgType(data, lnwire.MsgUpdateFulfillHTLC)
// Create an empty message so that the FuzzHarness func can check
// if the max payload constraint is violated.
emptyMsg := lnwire.UpdateFulfillHTLC{}
// Pass the message into our general fuzz harness for wire messages! // Pass the message into our general fuzz harness for wire messages!
return harness(data, &emptyMsg) return harness(data)
} }