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"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
@ -77,6 +78,11 @@ func Encode(payReq *PaymentRequest) string {
|
|||||||
// Decode attempts to decode the zbase32 encoded payment request. If the
|
// Decode attempts to decode the zbase32 encoded payment request. If the
|
||||||
// trailing checksum doesn't match, then an error is returned.
|
// trailing checksum doesn't match, then an error is returned.
|
||||||
func Decode(payData string) (*PaymentRequest, error) {
|
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
|
// First we decode the zbase32 encoded string into a series of raw
|
||||||
// bytes.
|
// bytes.
|
||||||
payReqBytes, err := zbase32.DecodeString(payData)
|
payReqBytes, err := zbase32.DecodeString(payData)
|
||||||
|
Loading…
Reference in New Issue
Block a user