Skip to content

Commit

Permalink
netsync: Dont let limitAdd shrink map below limit.
Browse files Browse the repository at this point in the history
Without checking for pre-existing elements it was possible for limitAdd
to shrink a map below the limit.
  • Loading branch information
jholdstock authored and davecgh committed Sep 12, 2024
1 parent d2e603b commit e28f4e4
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/netsync/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,10 @@ func (m *SyncManager) handleInvMsg(imsg *invMsg) {
// evicting a random value if adding the new value would cause it to
// overflow the maximum allowed.
func limitAdd(m map[chainhash.Hash]struct{}, hash chainhash.Hash, limit int) {
// Nothing to do if entry is already in the map.
if _, exists := m[hash]; exists {
return
}
if len(m)+1 > limit {
// Remove a random entry from the map. For most compilers, Go's
// range statement iterates starting at a random item although
Expand Down

0 comments on commit e28f4e4

Please sign in to comment.