瀏覽代碼

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

p2p/discover: fix out-of-bounds issue
Péter Szilágyi 7 年之前
父節點
當前提交
0544a43c13
共有 1 個文件被更改,包括 1 次插入1 次删除
  1. 1 1
      p2p/discover/table.go

+ 1 - 1
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
 // with someone else or became active.
 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.
 		return nil
 	}