[General]: Fix upper bound check here (#885)

This commit is contained in:
Edo 2023-03-31 12:35:49 +02:00 committed by GitHub
parent b53781c0bc
commit 4aa8e8c7dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 7 deletions

View File

@ -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<bool>())
@ -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<unsigned char>(dest[i])))
const auto c = static_cast<unsigned char>(dest[i]);
if (IsBadChar(c))
{
return false;
}

View File

@ -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();