Skip to content

Commit 22b4966

Browse files
committed
Move [clean|str]SubVer writes/copyStats into a lock
1 parent 0f31872 commit 22b4966

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/net.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,10 @@ void CNode::copyStats(CNodeStats &stats)
610610
X(nTimeOffset);
611611
X(addrName);
612612
X(nVersion);
613-
X(cleanSubVer);
613+
{
614+
LOCK(cs_SubVer);
615+
X(cleanSubVer);
616+
}
614617
X(fInbound);
615618
X(fAddnode);
616619
X(nStartingHeight);

src/net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ class CNode
598598
// store the sanitized version in cleanSubVer. The original should be used when dealing with
599599
// the network or wire types and the cleaned string used when displayed or logged.
600600
std::string strSubVer, cleanSubVer;
601+
CCriticalSection cs_SubVer; // used for both cleanSubVer and strSubVer
601602
bool fWhitelisted; // This peer can bypass DoS banning.
602603
bool fFeeler; // If true this node is being used as a short lived feeler.
603604
bool fOneShot;

src/net_processing.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
12111211
int nVersion;
12121212
int nSendVersion;
12131213
std::string strSubVer;
1214+
std::string cleanSubVer;
12141215
int nStartingHeight = -1;
12151216
bool fRelay = true;
12161217

@@ -1246,6 +1247,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
12461247
vRecv >> addrFrom >> nNonce;
12471248
if (!vRecv.empty()) {
12481249
vRecv >> LIMITED_STRING(strSubVer, MAX_SUBVERSION_LENGTH);
1250+
cleanSubVer = SanitizeString(strSubVer);
12491251
}
12501252
if (!vRecv.empty()) {
12511253
vRecv >> nStartingHeight;
@@ -1273,8 +1275,11 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
12731275

12741276
pfrom->nServices = nServices;
12751277
pfrom->addrLocal = addrMe;
1276-
pfrom->strSubVer = strSubVer;
1277-
pfrom->cleanSubVer = SanitizeString(strSubVer);
1278+
{
1279+
LOCK(pfrom->cs_SubVer);
1280+
pfrom->strSubVer = strSubVer;
1281+
pfrom->cleanSubVer = cleanSubVer;
1282+
}
12781283
pfrom->nStartingHeight = nStartingHeight;
12791284
pfrom->fClient = !(nServices & NODE_NETWORK);
12801285
{
@@ -1330,7 +1335,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
13301335
remoteAddr = ", peeraddr=" + pfrom->addr.ToString();
13311336

13321337
LogPrintf("receive version message: %s: version %d, blocks=%d, us=%s, peer=%d%s\n",
1333-
pfrom->cleanSubVer, pfrom->nVersion,
1338+
cleanSubVer, pfrom->nVersion,
13341339
pfrom->nStartingHeight, addrMe.ToString(), pfrom->id,
13351340
remoteAddr);
13361341

0 commit comments

Comments
 (0)