From 801d2ec66644fb9bf155963c4c7f92389bb3f35b Mon Sep 17 00:00:00 2001 From: chao Date: Sat, 15 Jun 2019 22:40:21 -0700 Subject: [PATCH] add nil pointer protection when deserialize pubkey --- crypto/bls/bls.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crypto/bls/bls.go b/crypto/bls/bls.go index 1cc3d8d36..0d7ecdac6 100644 --- a/crypto/bls/bls.go +++ b/crypto/bls/bls.go @@ -2,6 +2,7 @@ package bls import ( "errors" + "fmt" "github.com/harmony-one/bls/ffi/go/bls" "github.com/harmony-one/harmony/internal/ctxerror" @@ -20,6 +21,9 @@ func RandPrivateKey() *bls.SecretKey { // BytesToBlsPublicKey converts bytes into bls.PublicKey pointer. func BytesToBlsPublicKey(bytes []byte) (*bls.PublicKey, error) { + if len(bytes) == 0 { + return nil, fmt.Errorf("[BytesToBlsPublicKey] bytes is empty") + } pubKey := &bls.PublicKey{} err := pubKey.Deserialize(bytes) return pubKey, err