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:
Olaoluwa Osuntokun 2017-01-29 14:57:57 -08:00
parent 629d276409
commit d94777acf6
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
1 changed files with 6 additions and 0 deletions

View File

@ -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)