From 5716940c312da532171df1e920bc57206ae308b4 Mon Sep 17 00:00:00 2001 From: furszy Date: Fri, 26 Nov 2021 18:34:13 -0300 Subject: [PATCH] net: Add missing locks in net.{cpp,h} * writing variable 'nTotalBytesRecv' requires holding mutex 'cs_totalBytesRecv' exclusively * writing variables 'nTotalBytesSent' require holding mutex 'cs_totalBytesSent' exclusively * writing variable 'vAddedNodes' requires holding mutex 'cs_vAddedNodes' exclusively Backports btc@63f21d27ee463dafc32982d1ac50a1032449dd36 without the nMaxOut* variable changes that we don't have. --- src/net.cpp | 10 ++++++++-- src/net.h | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 388a748eaa1c6..2272d602235b1 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1966,8 +1966,14 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions) { Init(connOptions); - nTotalBytesRecv = 0; - nTotalBytesSent = 0; + { + LOCK(cs_totalBytesRecv); + nTotalBytesRecv = 0; + } + { + LOCK(cs_totalBytesSent); + nTotalBytesSent = 0; + } if (fListen && !InitBinds(connOptions.vBinds, connOptions.vWhiteBinds)) { if (clientInterface) { diff --git a/src/net.h b/src/net.h index 18212599491a8..8d9a86a81e9a7 100644 --- a/src/net.h +++ b/src/net.h @@ -162,7 +162,10 @@ class CConnman nSendBufferMaxSize = connOptions.nSendBufferMaxSize; nReceiveFloodSize = connOptions.nReceiveFloodSize; vWhitelistedRange = connOptions.vWhitelistedRange; - vAddedNodes = connOptions.m_added_nodes; + { + LOCK(cs_vAddedNodes); + vAddedNodes = connOptions.m_added_nodes; + } } CConnman(uint64_t seed0, uint64_t seed1);