mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-26 13:42:49 +02:00
zpay32: validate empty routing hints when parsing r fields
This commit is contained in:
@@ -23,6 +23,15 @@ var (
|
|||||||
// ErrInvalidUTF8Description is returned if the invoice description is
|
// ErrInvalidUTF8Description is returned if the invoice description is
|
||||||
// not valid UTF-8.
|
// not valid UTF-8.
|
||||||
ErrInvalidUTF8Description = errors.New("description is not valid UTF-8")
|
ErrInvalidUTF8Description = errors.New("description is not valid UTF-8")
|
||||||
|
|
||||||
|
// ErrLengthNotMultipleOfHopHintLength is returned if the length of the
|
||||||
|
// route hint data is not a multiple of the hop hint length.
|
||||||
|
ErrLengthNotMultipleOfHopHint = errors.New("length is not a multiple " +
|
||||||
|
"of hop hint length")
|
||||||
|
|
||||||
|
// ErrEmptyRouteHint is returned if the route hint field contains no hop
|
||||||
|
// data.
|
||||||
|
ErrEmptyRouteHint = errors.New("route hint field contains no hop data")
|
||||||
)
|
)
|
||||||
|
|
||||||
// DecodeOption is a type that can be used to supply functional options to the
|
// DecodeOption is a type that can be used to supply functional options to the
|
||||||
@@ -576,8 +585,12 @@ func parseRouteHint(data []byte) ([]HopHint, error) {
|
|||||||
|
|
||||||
// Check that base256Data is a multiple of hopHintLen.
|
// Check that base256Data is a multiple of hopHintLen.
|
||||||
if len(base256Data)%hopHintLen != 0 {
|
if len(base256Data)%hopHintLen != 0 {
|
||||||
return nil, fmt.Errorf("expected length multiple of %d bytes, "+
|
return nil, ErrLengthNotMultipleOfHopHint
|
||||||
"got %d", hopHintLen, len(base256Data))
|
}
|
||||||
|
|
||||||
|
// Check for empty route hint
|
||||||
|
if len(base256Data) == 0 {
|
||||||
|
return nil, ErrEmptyRouteHint
|
||||||
}
|
}
|
||||||
|
|
||||||
var routeHint []HopHint
|
var routeHint []HopHint
|
||||||
|
Reference in New Issue
Block a user