From 349f832bd398942423273afffed447d19b884d3b Mon Sep 17 00:00:00 2001 From: ahadda5 Date: Sun, 27 Jun 2021 20:13:55 +0400 Subject: [PATCH] No length check in AggregatePublicKeys (#9105) * check of len and nil * minor edit * minor edit Co-authored-by: terence tsao --- shared/bls/blst/public_key.go | 3 +++ shared/bls/blst/public_key_test.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/shared/bls/blst/public_key.go b/shared/bls/blst/public_key.go index 18f164b97ea..2dfaae6f022 100644 --- a/shared/bls/blst/public_key.go +++ b/shared/bls/blst/public_key.go @@ -57,6 +57,9 @@ func AggregatePublicKeys(pubs [][]byte) (common.PublicKey, error) { if featureconfig.Get().SkipBLSVerify { return &PublicKey{}, nil } + if pubs == nil || len(pubs) == 0 { + return nil, errors.New("nil or empty public keys") + } agg := new(blstAggregatePublicKey) mulP1 := make([]*blstPublicKey, 0, len(pubs)) for _, pubkey := range pubs { diff --git a/shared/bls/blst/public_key_test.go b/shared/bls/blst/public_key_test.go index bfae3025f99..e086e5b0fd5 100644 --- a/shared/bls/blst/public_key_test.go +++ b/shared/bls/blst/public_key_test.go @@ -76,3 +76,9 @@ func TestPublicKey_Copy(t *testing.T) { require.DeepEqual(t, pubkeyA.Marshal(), pubkeyBytes, "Pubkey was mutated after copy") } + +func TestPublicKeysEmpty(t *testing.T) { + pubs := [][]byte{} + _, err := blst.AggregatePublicKeys(pubs) + require.ErrorContains(t, "nil or empty public keys", err) +}