Skip to content

Commit

Permalink
sets client version and compare it by the first word, without symbols…
Browse files Browse the repository at this point in the history
… and in a case insensitive way
  • Loading branch information
pedro-at-decenomy committed Jul 29, 2021
1 parent d7363ff commit ce3b37a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/clientversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* for both aezorad and aezora-qt, to make it harder for attackers to
* target servers or GUI users specifically.
*/
const std::string CLIENT_NAME("AEZORA");
const std::string CLIENT_NAME("Aezora Core");

/**
* Client version number
Expand Down
16 changes: 15 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5114,7 +5114,21 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
pfrom->cleanSubVer = cleanSubVer;
}

if (pfrom->cleanSubVer.find(CLIENT_NAME) == std::string::npos) {
auto shortFromName = pfrom->cleanSubVer.substr(0, pfrom->cleanSubVer.find(' '));
auto shortName = CLIENT_NAME.substr(0, CLIENT_NAME.find(' '));

for (auto & c: shortFromName) c = toupper(c);
for (auto & c: shortName) c = toupper(c);

shortFromName.erase(
std::remove_if(
shortFromName.begin(),
shortFromName.end(),
[]( char const& c ) -> bool { return !std::isalnum(c); }),
shortFromName.end()
);

if (shortName.find(shortFromName) == std::string::npos) {
LOCK(cs_main);
Misbehaving(pfrom->GetId(), 100);
pfrom->fDisconnect = true;
Expand Down

0 comments on commit ce3b37a

Please sign in to comment.