Skip to content

Commit fa8548c

Browse files
author
MarcoFalke
committed
net: Remove unused unsanitized user agent string CNode::strSubVer
1 parent 7b13c64 commit fa8548c

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
@@ -1782,7 +1782,6 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
17821782
ServiceFlags nServices;
17831783
int nVersion;
17841784
int nSendVersion;
1785-
std::string strSubVer;
17861785
std::string cleanSubVer;
17871786
int nStartingHeight = -1;
17881787
bool fRelay = true;
@@ -1819,6 +1818,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
18191818
if (!vRecv.empty())
18201819
vRecv >> addrFrom >> nNonce;
18211820
if (!vRecv.empty()) {
1821+
std::string strSubVer;
18221822
vRecv >> LIMITED_STRING(strSubVer, MAX_SUBVERSION_LENGTH);
18231823
cleanSubVer = SanitizeString(strSubVer);
18241824
}
@@ -1850,7 +1850,6 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
18501850
pfrom->SetAddrLocal(addrMe);
18511851
{
18521852
LOCK(pfrom->cs_SubVer);
1853-
pfrom->strSubVer = strSubVer;
18541853
pfrom->cleanSubVer = cleanSubVer;
18551854
}
18561855
pfrom->nStartingHeight = nStartingHeight;

0 commit comments

Comments
 (0)