Skip to content

Commit

Permalink
Fix block: add more input validity check for votes
Browse files Browse the repository at this point in the history
  • Loading branch information
hijung committed Aug 28, 2023
1 parent b986812 commit 3439c53
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion icon/blockv0/blockvote.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (s *BlockVoteList) RLPDecodeSelf(d codec.Decoder) error {
if e == nil {
s.votes[i] = nil
} else {
if len(cbvl.Sharable) <= int(e.SharableIndex) {
if e.SharableIndex < 0 || int(e.SharableIndex) >= len(cbvl.Sharable) {
return errors.Errorf("invalid sharable index len(Sharable)=%d index=%d", len(cbvl.Sharable), e.SharableIndex)
}
s.votes[i] = &BlockVote{
Expand Down
8 changes: 8 additions & 0 deletions icon/blockv0/leadervote.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,19 @@ func (s *LeaderVoteList) RLPDecodeSelf(d codec.Decoder) error {
if err != nil {
return err
}
for i, sh := range cbvl.Sharable {
if sh.Round == nil && sh.Round_ == nil {
return errors.Errorf("LeaderVote with no round height=%d sharable index=%d", sh.BlockHeight, i)
}
}
s.votes = make([]*LeaderVote, len(cbvl.Entries))
for i, e := range cbvl.Entries {
if e==nil {
s.votes[i] = nil
} else {
if e.SharableIndex < 0 || int(e.SharableIndex) >= len(cbvl.Sharable) {
return errors.Errorf("invalid sharable index len(Sharable)=%d index=%d", len(cbvl.Sharable), e.SharableIndex)
}
s.votes[i] = &LeaderVote{
cbvl.Sharable[e.SharableIndex],
e.LeaderVoteIndividual,
Expand Down

0 comments on commit 3439c53

Please sign in to comment.