Skip to content

Commit

Permalink
No length check in AggregatePublicKeys (#9105)
Browse files Browse the repository at this point in the history
* check of len and nil

* minor edit

* minor edit

Co-authored-by: terence tsao <terence@prysmaticlabs.com>
  • Loading branch information
ahadda5 and terencechain committed Jun 27, 2021
1 parent a860648 commit 349f832
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions shared/bls/blst/public_key.go
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions shared/bls/blst/public_key_test.go
Expand Up @@ -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)
}

0 comments on commit 349f832

Please sign in to comment.