fix: GenNewKeyRing should return out of bound error if s and ring size equal in value (#412)

This commit is contained in:
Banana-J 2024-01-29 11:27:48 +11:00 committed by GitHub
parent 743fc8500b
commit cac03bd960
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,9 +8,10 @@ import (
"encoding/binary" "encoding/binary"
"errors" "errors"
"fmt" "fmt"
"github.com/XinFinOrg/XDPoSChain/common"
"math/big" "math/big"
"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/crypto" "github.com/XinFinOrg/XDPoSChain/crypto"
"github.com/XinFinOrg/XDPoSChain/log" "github.com/XinFinOrg/XDPoSChain/log"
) )
@ -273,7 +274,7 @@ func GenNewKeyRing(size int, privkey *ecdsa.PrivateKey, s int) ([]*ecdsa.PublicK
ring := make([]*ecdsa.PublicKey, size) ring := make([]*ecdsa.PublicKey, size)
pubkey := privkey.Public().(*ecdsa.PublicKey) pubkey := privkey.Public().(*ecdsa.PublicKey)
if s > len(ring) { if s >= len(ring) {
return nil, errors.New("index s out of bounds") return nil, errors.New("index s out of bounds")
} }