mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-10 14:17:56 +01:00
zpay32: validate UTF-8 parsing field description
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
||||||
@@ -18,6 +19,12 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ErrInvalidUTF8Description is returned if the invoice description is
|
||||||
|
// not valid UTF-8.
|
||||||
|
ErrInvalidUTF8Description = errors.New("description is not valid UTF-8")
|
||||||
|
)
|
||||||
|
|
||||||
// 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
|
||||||
// Decode function.
|
// Decode function.
|
||||||
type DecodeOption func(*decodeOptions)
|
type DecodeOption func(*decodeOptions)
|
||||||
@@ -446,6 +453,10 @@ func parseDescription(data []byte) (*string, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !utf8.Valid(base256Data) {
|
||||||
|
return nil, ErrInvalidUTF8Description
|
||||||
|
}
|
||||||
|
|
||||||
description := string(base256Data)
|
description := string(base256Data)
|
||||||
|
|
||||||
return &description, nil
|
return &description, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user