lnwire: validate that gossip messages contain valid TLV

In this commit, we check that the extra bytes appended to gossip
messages contain valid TLV streams. We do this here for:
- channel_announcement
- channel_announcement_2
- channel_update
- channel_update_2
- node_announcement

This is in preparation for the SQL version of the graph store which will
normalise TLV streams at persistence time.
This commit is contained in:
Elle Mouton committed 2025-05-22 14:14:41 +02:00
1 parent 0db91304cf
commit 1410a0949d
7 files changed
+47 -9

No files matched your search

+7 -2
View File
@@ -112,8 +112,8 @@ var _ SizeableMessage = (*NodeAnnouncement)(nil)
// io.Reader observing the specified protocol version.
//
// This is part of the lnwire.Message interface.
func (a *NodeAnnouncement) Decode(r io.Reader, pver uint32) error {
return ReadElements(r,
func (a *NodeAnnouncement) Decode(r io.Reader, _ uint32) error {
err := ReadElements(r,
&a.Signature,
&a.Features,
&a.Timestamp,
@@ -123,6 +123,11 @@ func (a *NodeAnnouncement) Decode(r io.Reader, pver uint32) error {
&a.Addresses,
&a.ExtraOpaqueData,
)
if err != nil {
return err
}
return a.ExtraOpaqueData.ValidateTLV()
}
// Encode serializes the target NodeAnnouncement into the passed io.Writer