consensus: HasVoteMessage index boundary check (#7720)

Went through #2871, there are several issues, this PR tries to tackle the `HasVoteMessage` with an invalid validator index sent by a bad peer and it prevents the bad vote goes to the peerMsgQueue.

Future work, check other bad message cases and plumbing the reactor errors with the peer manager and then can disconnect the peer sending the bad messages.
This commit is contained in:
JayT106
2022-02-21 13:21:24 +00:00
committed by GitHub
parent a185163c57
commit ce898a738c
5 changed files with 131 additions and 14 deletions
+2 -2
View File
@@ -72,7 +72,7 @@ func (bA *BitArray) getIndex(i int) bool {
}
// SetIndex sets the bit at index i within the bit array.
// The behavior is undefined if i >= bA.Bits
// This method returns false if i is out of range of the BitArray.
func (bA *BitArray) SetIndex(i int, v bool) bool {
if bA == nil {
return false
@@ -83,7 +83,7 @@ func (bA *BitArray) SetIndex(i int, v bool) bool {
}
func (bA *BitArray) setIndex(i int, v bool) bool {
if i >= bA.Bits {
if i < 0 || i >= bA.Bits {
return false
}
if v {