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 committed Sep 11, 2024
1 parent f3d7099 commit 96eb6a3
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 @@ -1574,6 +1574,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 96eb6a3

Please sign in to comment.