add nil pointer protection when deserialize pubkey

pull/1075/head
chao 6 years ago committed by chaosma
parent 796dc630bb
commit 801d2ec666
  1. 4
      crypto/bls/bls.go

@ -2,6 +2,7 @@ package bls
import ( import (
"errors" "errors"
"fmt"
"github.com/harmony-one/bls/ffi/go/bls" "github.com/harmony-one/bls/ffi/go/bls"
"github.com/harmony-one/harmony/internal/ctxerror" "github.com/harmony-one/harmony/internal/ctxerror"
@ -20,6 +21,9 @@ func RandPrivateKey() *bls.SecretKey {
// BytesToBlsPublicKey converts bytes into bls.PublicKey pointer. // BytesToBlsPublicKey converts bytes into bls.PublicKey pointer.
func BytesToBlsPublicKey(bytes []byte) (*bls.PublicKey, error) { func BytesToBlsPublicKey(bytes []byte) (*bls.PublicKey, error) {
if len(bytes) == 0 {
return nil, fmt.Errorf("[BytesToBlsPublicKey] bytes is empty")
}
pubKey := &bls.PublicKey{} pubKey := &bls.PublicKey{}
err := pubKey.Deserialize(bytes) err := pubKey.Deserialize(bytes)
return pubKey, err return pubKey, err

Loading…
Cancel
Save