Skip to content

Commit c384800

Browse files
committed
Merge pull request #6462
7b79cbd limit total length of user agent comments (Pavol Rusnak) 557f8ea implement uacomment config parameter which can add comments to user agent as per BIP-0014 (Pavol Rusnak)
2 parents c9c017a + 7b79cbd commit c384800

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

Diff for: src/init.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,13 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
10201020

10211021
RegisterNodeSignals(GetNodeSignals());
10221022

1023+
// format user agent, check total size
1024+
strSubVersion = FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, mapMultiArgs.count("-uacomment") ? mapMultiArgs["-uacomment"] : std::vector<string>());
1025+
if (strSubVersion.size() > MAX_SUBVERSION_LENGTH) {
1026+
return InitError(strprintf("Total length of network version string %i exceeds maximum of %i characters. Reduce the number and/or size of uacomments.",
1027+
strSubVersion.size(), MAX_SUBVERSION_LENGTH));
1028+
}
1029+
10231030
if (mapArgs.count("-onlynet")) {
10241031
std::set<enum Network> nets;
10251032
BOOST_FOREACH(const std::string& snet, mapMultiArgs["-onlynet"]) {

Diff for: src/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3898,7 +3898,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
38983898
if (!vRecv.empty())
38993899
vRecv >> addrFrom >> nNonce;
39003900
if (!vRecv.empty()) {
3901-
vRecv >> LIMITED_STRING(pfrom->strSubVer, 256);
3901+
vRecv >> LIMITED_STRING(pfrom->strSubVer, MAX_SUBVERSION_LENGTH);
39023902
pfrom->cleanSubVer = SanitizeString(pfrom->strSubVer);
39033903
}
39043904
if (!vRecv.empty())

Diff for: src/net.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ CAddrMan addrman;
8383
int nMaxConnections = DEFAULT_MAX_PEER_CONNECTIONS;
8484
int nWhiteConnections = 0;
8585
bool fAddressesInitialized = false;
86+
std::string strSubVersion;
8687

8788
vector<CNode*> vNodes;
8889
CCriticalSection cs_vNodes;
@@ -445,7 +446,7 @@ void CNode::PushVersion()
445446
else
446447
LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), id);
447448
PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe,
448-
nLocalHostNonce, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<string>()), nBestHeight, true);
449+
nLocalHostNonce, strSubVersion, nBestHeight, true);
449450
}
450451

451452

Diff for: src/net.h

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ static const unsigned int MAX_INV_SZ = 50000;
4646
static const unsigned int MAX_ADDR_TO_SEND = 1000;
4747
/** Maximum length of incoming protocol messages (no message over 2 MiB is currently acceptable). */
4848
static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 2 * 1024 * 1024;
49+
/** Maximum length of strSubVer in `version` message */
50+
static const unsigned int MAX_SUBVERSION_LENGTH = 256;
4951
/** -listen default */
5052
static const bool DEFAULT_LISTEN = true;
5153
/** -upnp default */
@@ -168,6 +170,9 @@ extern CCriticalSection cs_vAddedNodes;
168170
extern NodeId nLastNodeId;
169171
extern CCriticalSection cs_nLastNodeId;
170172

173+
/** Subversion as sent to the P2P network in `version` messages */
174+
extern std::string strSubVersion;
175+
171176
struct LocalServiceInfo {
172177
int nScore;
173178
int nPort;

Diff for: src/rpcnet.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,7 @@ UniValue getnetworkinfo(const UniValue& params, bool fHelp)
443443

444444
UniValue obj(UniValue::VOBJ);
445445
obj.push_back(Pair("version", CLIENT_VERSION));
446-
obj.push_back(Pair("subversion",
447-
FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<string>())));
446+
obj.push_back(Pair("subversion", strSubVersion));
448447
obj.push_back(Pair("protocolversion",PROTOCOL_VERSION));
449448
obj.push_back(Pair("localservices", strprintf("%016x", nLocalServices)));
450449
obj.push_back(Pair("timeoffset", GetTimeOffset()));

0 commit comments

Comments
 (0)