invoice: sanity check routing info field

This commit allows parseRoutingInfo to return an error when parsing a
routing info field whose length is not a multiple of 51 bytes, rather
than crash.
This commit is contained in:
Wilmer Paulino 2018-01-09 01:04:58 -05:00
parent db7154a401
commit fa2cc57ca6
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F

@ -37,6 +37,10 @@ const (
// with zeroes.
pubKeyBase32Len = 53
// routingInfoLen is the number of bytes needed to encode the extra
// routing info of a single private route.
routingInfoLen = 51
// The following byte values correspond to the supported field types.
// The field name is the character representing that 5-bit value in the
// bech32 string.
@ -860,6 +864,11 @@ func parseRoutingInfo(data []byte) ([]ExtraRoutingInfo, error) {
return nil, err
}
if len(base256Data)%routingInfoLen != 0 {
return nil, fmt.Errorf("expected length multiple of %d bytes, got %d",
routingInfoLen, len(base256Data))
}
var routingInfo []ExtraRoutingInfo
info := ExtraRoutingInfo{}
for len(base256Data) > 0 {