From 5f33db9ed66ae40ecdba0b89acce3b86a3d009d4 Mon Sep 17 00:00:00 2001 From: Edo Date: Sat, 11 Mar 2023 12:35:03 +0000 Subject: [PATCH] [General]: Add size check to execute func (#827) --- src/Components/Modules/Command.cpp | 24 ++++++------------------ src/Components/Modules/Command.hpp | 1 - src/Components/Modules/Dvar.cpp | 2 +- src/Game/Functions.hpp | 2 ++ 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/Components/Modules/Command.cpp b/src/Components/Modules/Command.cpp index fca3a947..0aa4430c 100644 --- a/src/Components/Modules/Command.cpp +++ b/src/Components/Modules/Command.cpp @@ -85,11 +85,9 @@ namespace Components if (Loader::IsPregame()) { MessageBoxA(nullptr, "Registering server commands in pregame state is illegal!", nullptr, MB_ICONERROR); - #ifdef _DEBUG __debugbreak(); #endif - return; } @@ -120,6 +118,8 @@ namespace Components { command.append("\n"); // Make sure it's terminated + assert(command.size() < Game::MAX_CMD_LINE); + if (sync) { Game::Cmd_ExecuteSingleCommand(0, 0, command.data()); @@ -134,9 +134,9 @@ namespace Components { auto* cmdFunction = *Game::cmd_functions; - while (cmdFunction != nullptr) + while (cmdFunction) { - if (cmdFunction->name != nullptr && cmdFunction->name == command) + if (cmdFunction->name && Utils::String::Compare(cmdFunction->name, command)) { return cmdFunction; } @@ -174,18 +174,6 @@ namespace Components } } - bool Command::IsSendingNotifiesDisabled() - { - static std::optional flag; - - if (!flag.has_value()) - { - flag.emplace(Flags::HasFlag("disable-notifies")); - } - - return flag.value(); - } - const std::vector& Command::GetExceptions() { static const auto exceptions = []() -> std::vector @@ -197,7 +185,7 @@ namespace Components "map", }; - if (IsSendingNotifiesDisabled()) + if (Flags::HasFlag("disable-notifies")) { values.emplace_back("vstr"); values.emplace_back("wait"); @@ -219,7 +207,7 @@ namespace Components const auto& exceptions = GetExceptions(); for (const auto& entry : exceptions) { - if (!_stricmp(cmd, entry.data())) + if (Utils::String::Compare(cmd, entry)) { return false; } diff --git a/src/Components/Modules/Command.hpp b/src/Components/Modules/Command.hpp index e060b456..57cc4f67 100644 --- a/src/Components/Modules/Command.hpp +++ b/src/Components/Modules/Command.hpp @@ -73,7 +73,6 @@ namespace Components static void MainCallback(); static void MainCallbackSV(); - static bool IsSendingNotifiesDisabled(); static const std::vector& GetExceptions(); static bool CL_ShouldSendNotify_Hk(const char* cmd); }; diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index 9029945f..dcf0c998 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -257,7 +257,7 @@ namespace Components void Dvar::SetFromStringByNameSafeExternal(const char* dvarName, const char* string) { - static std::array exceptions = + static std::array exceptions = { "ui_showEndOfGame", "systemlink", diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 322eb467..53f65385 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -585,6 +585,8 @@ namespace Game constexpr std::size_t MAX_LOCAL_CLIENTS = 1; constexpr std::size_t MAX_CLIENTS = 18; + constexpr auto MAX_CMD_BUFFER = 0x10000; + constexpr auto MAX_CMD_LINE = 0x1000; constexpr auto CMD_MAX_NESTING = 8; extern CmdArgs* cmd_args; extern CmdArgs* sv_cmd_args;