From 39a476dcb2ef05cdb6de61432fcc66df66975f4f Mon Sep 17 00:00:00 2001 From: Patrick Lodder Date: Fri, 17 Dec 2021 19:45:45 -0400 Subject: [PATCH] net: avoid uninitialized reads on counters Initialize CConnman byte counters during construction, so that GetTotalBytesRecv() and GetTotalBytesSent() methods don't return garbage before Start() is called, in QT. Backported from: 8313fa8e Original author: Russell Yanofsky --- src/net.cpp | 2 -- src/net.h | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 64e8eaad6..467abb4a2 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2217,8 +2217,6 @@ NodeId CConnman::GetNewNodeId() bool CConnman::Start(CScheduler& scheduler, std::string& strNodeError, Options connOptions) { - nTotalBytesRecv = 0; - nTotalBytesSent = 0; nMaxOutboundTotalBytesSentInCycle = 0; nMaxOutboundCycleStartTime = 0; diff --git a/src/net.h b/src/net.h index bbde0e336..d823ae626 100644 --- a/src/net.h +++ b/src/net.h @@ -339,8 +339,8 @@ private: // Network usage totals CCriticalSection cs_totalBytesRecv; CCriticalSection cs_totalBytesSent; - uint64_t nTotalBytesRecv; - uint64_t nTotalBytesSent; + uint64_t nTotalBytesRecv = 0; + uint64_t nTotalBytesSent = 0; // outbound limit & stats uint64_t nMaxOutboundTotalBytesSentInCycle;