Skip to content

Commit 16187f0

Browse files
committed
zpay32: validate empty routing hints when parsing r fields
1 parent b8acca2 commit 16187f0

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

zpay32/decode.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ var (
2323
// ErrInvalidUTF8Description is returned if the invoice description is
2424
// not valid UTF-8.
2525
ErrInvalidUTF8Description = errors.New("description is not valid UTF-8")
26+
27+
// ErrLengthNotMultipleOfHopHintLength is returned if the length of the
28+
// route hint data is not a multiple of the hop hint length.
29+
ErrLengthNotMultipleOfHopHint = errors.New("length is not a multiple " +
30+
"of hop hint length")
31+
32+
// ErrEmptyRouteHint is returned if the route hint field contains no hop
33+
// data.
34+
ErrEmptyRouteHint = errors.New("route hint field contains no hop data")
2635
)
2736

2837
// DecodeOption is a type that can be used to supply functional options to the
@@ -576,8 +585,12 @@ func parseRouteHint(data []byte) ([]HopHint, error) {
576585

577586
// Check that base256Data is a multiple of hopHintLen.
578587
if len(base256Data)%hopHintLen != 0 {
579-
return nil, fmt.Errorf("expected length multiple of %d bytes, "+
580-
"got %d", hopHintLen, len(base256Data))
588+
return nil, ErrLengthNotMultipleOfHopHint
589+
}
590+
591+
// Check for empty route hint
592+
if len(base256Data) == 0 {
593+
return nil, ErrEmptyRouteHint
581594
}
582595

583596
var routeHint []HopHint

0 commit comments

Comments
 (0)