From 33bda6ab87cc1b569e96da337296eb3e9ce6db1a Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 26 Jan 2022 16:38:21 +0200 Subject: [PATCH] Fix data race condition in BanMan::DumpBanlist() The m_is_dirty value being read in BannedSetIsDirty() can differ from the value being set in SweepBanned(), i.e., be inconsistent with a BanMan instance internal state. --- src/banman.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/banman.cpp b/src/banman.cpp index 7fa489b0514..2b029198db3 100644 --- a/src/banman.cpp +++ b/src/banman.cpp @@ -43,9 +43,11 @@ void BanMan::DumpBanlist() static Mutex dump_mutex; LOCK(dump_mutex); - SweepBanned(); // clean unused entries (if bantime has expired) - - if (!BannedSetIsDirty()) return; + { + LOCK(m_cs_banned); + SweepBanned(); + if (!BannedSetIsDirty()) return; + } int64_t n_start = GetTimeMillis();