lnwire: ensure zlib short chan id's are sorted

This commit is contained in:
Olaoluwa Osuntokun 2018-06-25 16:15:30 -07:00
parent 940b95aad7
commit 23b1678266
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -181,7 +181,10 @@ func decodeShortChanIDs(r io.Reader) (ShortChanIDEncoding, []ShortChannelID, err
return 0, nil, fmt.Errorf("unable to create zlib reader: %v", err) return 0, nil, fmt.Errorf("unable to create zlib reader: %v", err)
} }
var shortChanIDs []ShortChannelID var (
shortChanIDs []ShortChannelID
lastChanID ShortChannelID
)
for { for {
// We'll now attempt to read the next short channel ID // We'll now attempt to read the next short channel ID
// encoded in the payload. // encoded in the payload.
@ -208,6 +211,18 @@ func decodeShortChanIDs(r io.Reader) (ShortChanIDEncoding, []ShortChannelID, err
// We successfully read the next ID, so well collect // We successfully read the next ID, so well collect
// that in the set of final ID's to return. // that in the set of final ID's to return.
shortChanIDs = append(shortChanIDs, cid) shortChanIDs = append(shortChanIDs, cid)
// Finally, we'll ensure that this short chan ID is
// greater than the last one. This is a requirement
// within the encoding, and if violated can aide us in
// detecting malicious payloads.
if cid.ToUint64() <= lastChanID.ToUint64() {
return 0, nil, fmt.Errorf("current sid of %v "+
"isn't greater than last sid of %v", cid,
lastChanID)
}
lastChanID = cid
} }
default: default: