Skip to content

Commit c83442e

Browse files
author
MarcoFalke
committed
Merge #15654: net: Remove unused unsanitized user agent string CNode::strSubVer
fa8548c net: Remove unused unsanitized user agent string CNode::strSubVer (MarcoFalke) Pull request description: I fail to see a use case for this unsanitized byte array. In fact this can easily be confused with `cleanSubVer` and be displayed to the user (or logged) by a simple typo that is hard to find in review. Further reading: https://btcinformation.org/en/developer-reference#version ACKs for commit fa8548: promag: utACK fa8548c, good catch. practicalswift: utACK fa8548c sipa: utACK fa8548c Tree-SHA512: 3c3ff1504d1583ad099df9a6aa761458a82ec48a58ef7aaa9b5679a5281dd1b59036ba2932ed708488951a565b669a3083ef70be5a58472ff8677b971162ae2f
2 parents daef20f + fa8548c commit c83442e

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

src/net.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2627,7 +2627,6 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
26272627
{
26282628
hSocket = hSocketIn;
26292629
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
2630-
strSubVer = "";
26312630
hashContinue = uint256();
26322631
filterInventoryKnown.reset();
26332632
pfilter = MakeUnique<CBloomFilter>();

src/net.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static const unsigned int MAX_LOCATOR_SZ = 101;
5353
static const unsigned int MAX_ADDR_TO_SEND = 1000;
5454
/** Maximum length of incoming protocol messages (no message over 4 MB is currently acceptable). */
5555
static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000;
56-
/** Maximum length of strSubVer in `version` message */
56+
/** Maximum length of the user agent string in `version` message */
5757
static const unsigned int MAX_SUBVERSION_LENGTH = 256;
5858
/** Maximum number of automatic outgoing nodes */
5959
static const int MAX_OUTBOUND_CONNECTIONS = 8;
@@ -650,12 +650,12 @@ class CNode
650650
// Bind address of our side of the connection
651651
const CAddress addrBind;
652652
std::atomic<int> nVersion{0};
653-
// strSubVer is whatever byte array we read from the wire. However, this field is intended
654-
// to be printed out, displayed to humans in various forms and so on. So we sanitize it and
655-
// store the sanitized version in cleanSubVer. The original should be used when dealing with
656-
// the network or wire types and the cleaned string used when displayed or logged.
657-
std::string strSubVer GUARDED_BY(cs_SubVer), cleanSubVer GUARDED_BY(cs_SubVer);
658-
CCriticalSection cs_SubVer; // used for both cleanSubVer and strSubVer
653+
RecursiveMutex cs_SubVer;
654+
/**
655+
* cleanSubVer is a sanitized string of the user agent byte array we read
656+
* from the wire. This cleaned string can safely be logged or displayed.
657+
*/
658+
std::string cleanSubVer GUARDED_BY(cs_SubVer){};
659659
bool m_prefer_evict{false}; // This peer is preferred for eviction.
660660
bool fWhitelisted{false}; // This peer can bypass DoS banning.
661661
bool fFeeler{false}; // If true this node is being used as a short lived feeler.

src/net_processing.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,6 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
18431843
ServiceFlags nServices;
18441844
int nVersion;
18451845
int nSendVersion;
1846-
std::string strSubVer;
18471846
std::string cleanSubVer;
18481847
int nStartingHeight = -1;
18491848
bool fRelay = true;
@@ -1880,6 +1879,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
18801879
if (!vRecv.empty())
18811880
vRecv >> addrFrom >> nNonce;
18821881
if (!vRecv.empty()) {
1882+
std::string strSubVer;
18831883
vRecv >> LIMITED_STRING(strSubVer, MAX_SUBVERSION_LENGTH);
18841884
cleanSubVer = SanitizeString(strSubVer);
18851885
}
@@ -1911,7 +1911,6 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
19111911
pfrom->SetAddrLocal(addrMe);
19121912
{
19131913
LOCK(pfrom->cs_SubVer);
1914-
pfrom->strSubVer = strSubVer;
19151914
pfrom->cleanSubVer = cleanSubVer;
19161915
}
19171916
pfrom->nStartingHeight = nStartingHeight;

0 commit comments

Comments
 (0)