zpay32: validate empty routing hints when parsing r fields

This commit is contained in:
MPins
2025-06-24 17:52:30 -03:00
committed by MPins
parent b8acca2c89
commit 16187f047a

View File

@@ -23,6 +23,15 @@ var (
// ErrInvalidUTF8Description is returned if the invoice 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
@@ -576,8 +585,12 @@ func parseRouteHint(data []byte) ([]HopHint, error) {
// Check that base256Data is a multiple of hopHintLen.
if len(base256Data)%hopHintLen != 0 {
return nil, fmt.Errorf("expected length multiple of %d bytes, "+
"got %d", hopHintLen, len(base256Data))
return nil, ErrLengthNotMultipleOfHopHint
}
// Check for empty route hint
if len(base256Data) == 0 {
return nil, ErrEmptyRouteHint
}
var routeHint []HopHint