From d5e9ef763d039fb9bbbc93fbf46ece8498b08a7f Mon Sep 17 00:00:00 2001 From: Duke Date: Wed, 18 Jan 2023 23:02:41 -0500 Subject: [PATCH] Prevent coredump when -proxy=... -externalip=... is used Replace an assert() in Unserialize() with the actual behavior we want, i.e. making sure that vRandom is empty. Before the assert() was added, the code called Clear() which ensured vRandom was empty. Clear() was changed to the assert() in BTC commit b138973a8b4bbe061ad97011f278a21e08ea79e6 to prevent recursive locks but risks crashing the node. Instead, we just empty out vRandom. The addition of EXCLUSIVE_LOCKS_REQUIRED is not needed to fix this but seems prudent since Serialize() has it and the original code from BTC has EXCLUSIVE_LOCKS_REQUIRED on all the methods of this class. As a side note, crashing a full node with an assert() and possibly corrupting the wallet.dat, block files and other data is REALLY FUCKING DUMB. Instead, code should be written to prevent the possibility of crashing or throw an exception with a useful error. --- src/addrman.h | 4 ++-- src/net.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/addrman.h b/src/addrman.h index ab425d40e..1abe9bf12 100644 --- a/src/addrman.h +++ b/src/addrman.h @@ -435,11 +435,11 @@ public: } template - void Unserialize(Stream& s_) + void Unserialize(Stream& s_) EXCLUSIVE_LOCKS_REQUIRED(!cs) { LOCK(cs); - assert(vRandom.empty()); + std::vector().swap(vRandom); Format format; s_ >> Using>(format); diff --git a/src/net.cpp b/src/net.cpp index 66604b1a5..75ae7cb0b 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2277,8 +2277,8 @@ void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler) } uiInterface.InitMessage(_("Loading addresses...")); - // Load addresses for peers.dat int64_t nStart = GetTimeMillis(); + fprintf(stderr, "%s: Loading addresses for peers.dat at %ld\n", __func__, nStart); { CAddrDB adb; if (!adb.Read(addrman))