From 4aa8e8c7ddb33bcc39001ed838b57e51c9d9a1c8 Mon Sep 17 00:00:00 2001 From: Edo Date: Fri, 31 Mar 2023 12:35:49 +0200 Subject: [PATCH] [General]: Fix upper bound check here (#885) --- src/Components/Modules/PlayerName.cpp | 24 +++++++++++++++++------- src/Components/Modules/PlayerName.hpp | 2 ++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Components/Modules/PlayerName.cpp b/src/Components/Modules/PlayerName.cpp index 352e8d3c..df583669 100644 --- a/src/Components/Modules/PlayerName.cpp +++ b/src/Components/Modules/PlayerName.cpp @@ -6,6 +6,21 @@ namespace Components { Dvar::Var PlayerName::sv_allowColoredNames; + bool PlayerName::IsBadChar(int c) + { + if (c == '%') + { + return true; + } + + if (c < 32 || c > 126) + { + return true; + } + + return false; + } + void PlayerName::UserInfoCopy(char* buffer, const char* name, const int size) { if (!sv_allowColoredNames.get()) @@ -71,13 +86,8 @@ namespace Components while (i < size - 1 && dest[i] != '\0') { // Check for various illegal characters - - if (dest[i] == '%') - { - return false; - } - - if (std::iscntrl(static_cast(dest[i]))) + const auto c = static_cast(dest[i]); + if (IsBadChar(c)) { return false; } diff --git a/src/Components/Modules/PlayerName.hpp b/src/Components/Modules/PlayerName.hpp index fb8641b4..f216e14e 100644 --- a/src/Components/Modules/PlayerName.hpp +++ b/src/Components/Modules/PlayerName.hpp @@ -16,6 +16,8 @@ namespace Components // Message used when kicking players static constexpr auto INVALID_NAME_MSG = "Invalid name detected"; + static bool IsBadChar(int c); + static char* CleanStrStub(char* string); static void ClientCleanName();