invoice: sanity check empty fallback addr field

This commit allows parseFallbackAddr to return an error when parsing an
empty fallback address field, rather than crash.
This commit is contained in:
Wilmer Paulino 2018-01-09 01:01:24 -05:00
parent 00d530bd91
commit db7154a401
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F

@ -797,7 +797,13 @@ func parseMinFinalCLTVExpiry(data []byte) (*uint64, error) {
// parseFallbackAddr converts the data (encoded in base32) into a fallback
// on-chain address.
func parseFallbackAddr(data []byte, net *chaincfg.Params) (btcutil.Address, error) {
// Checks if the data is empty or contains a version without an address.
if len(data) < 2 {
return nil, fmt.Errorf("empty fallback address field")
}
var addr btcutil.Address
version := data[0]
switch version {
case 0: