diff options
author | MarcoFalke <falke.marco@gmail.com> | 2015-09-09 14:24:56 +0200 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2015-09-16 15:23:29 +0200 |
commit | 1c1b1b315f2f89584abe9a7558945dea2fbee708 (patch) | |
tree | 80c5e16ed073213d4645f88eb42c398ed194c27f /src/init.cpp | |
parent | 536207f3167daad1fa3d60a1de7d9cb55db28ac9 (diff) |
[uacomment] Sanitize per BIP-0014
* SanitizeString() can be requested to be more strict
* Throw error when SanitizeString() changes uacomments
* Fix tests
Diffstat (limited to 'src/init.cpp')
-rw-r--r-- | src/init.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/init.cpp b/src/init.cpp index 5759b4b428..2239cc0724 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1014,8 +1014,15 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) RegisterNodeSignals(GetNodeSignals()); - // format user agent, check total size - strSubVersion = FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, mapMultiArgs.count("-uacomment") ? mapMultiArgs["-uacomment"] : std::vector<string>()); + // sanitize comments per BIP-0014, format user agent and check total size + std::vector<string> uacomments; + BOOST_FOREACH(string cmt, mapMultiArgs["-uacomment"]) + { + if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT)) + return InitError(strprintf("User Agent comment (%s) contains unsafe characters.", cmt)); + uacomments.push_back(SanitizeString(cmt, SAFE_CHARS_UA_COMMENT)); + } + strSubVersion = FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, uacomments); if (strSubVersion.size() > MAX_SUBVERSION_LENGTH) { return InitError(strprintf("Total length of network version string %i exceeds maximum of %i characters. Reduce the number and/or size of uacomments.", strSubVersion.size(), MAX_SUBVERSION_LENGTH)); |