From e28f4e420b879d900f920a1afc7cba0bf3073618 Mon Sep 17 00:00:00 2001 From: jholdstock Date: Wed, 11 Sep 2024 11:19:26 +0100 Subject: [PATCH] netsync: Dont let limitAdd shrink map below limit. Without checking for pre-existing elements it was possible for limitAdd to shrink a map below the limit. --- internal/netsync/manager.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/netsync/manager.go b/internal/netsync/manager.go index 2b3504101..f5f22b999 100644 --- a/internal/netsync/manager.go +++ b/internal/netsync/manager.go @@ -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