Merge pull request #16085 from karalabe/p2p-fix-outofbounds

p2p/discover: fix out-of-bounds issue
pull/16087/head
Péter Szilágyi 7 years ago committed by GitHub
commit 0544a43c13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      p2p/discover/table.go

@ -763,7 +763,7 @@ func (tab *Table) addReplacement(b *bucket, n *Node) {
// last entry in the bucket. If 'last' isn't the last entry, it has either been replaced // last entry in the bucket. If 'last' isn't the last entry, it has either been replaced
// with someone else or became active. // with someone else or became active.
func (tab *Table) replace(b *bucket, last *Node) *Node { func (tab *Table) replace(b *bucket, last *Node) *Node {
if len(b.entries) >= 0 && b.entries[len(b.entries)-1].ID != last.ID { if len(b.entries) == 0 || b.entries[len(b.entries)-1].ID != last.ID {
// Entry has moved, don't replace it. // Entry has moved, don't replace it.
return nil return nil
} }

Loading…
Cancel
Save