mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
zpay32: ensure argument to Decode is not an empty string
This commit fixes a possible panic which can arise within the library due to poor user-data. We now explicitly check for an empty string, exiting early if found within the Decode method.
This commit is contained in:
parent
629d276409
commit
d94777acf6
@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
|
||||
@ -77,6 +78,11 @@ func Encode(payReq *PaymentRequest) string {
|
||||
// Decode attempts to decode the zbase32 encoded payment request. If the
|
||||
// trailing checksum doesn't match, then an error is returned.
|
||||
func Decode(payData string) (*PaymentRequest, error) {
|
||||
if payData == "" {
|
||||
return nil, fmt.Errorf("encoded payment request must be a " +
|
||||
"non-empty string")
|
||||
}
|
||||
|
||||
// First we decode the zbase32 encoded string into a series of raw
|
||||
// bytes.
|
||||
payReqBytes, err := zbase32.DecodeString(payData)
|
||||
|
Loading…
Reference in New Issue
Block a user