[General]: Add size check to execute func (#827)

This commit is contained in:
Edo 2023-03-11 12:35:03 +00:00 committed by GitHub
parent b44aa534dc
commit 5f33db9ed6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 20 deletions

View File

@ -85,11 +85,9 @@ namespace Components
if (Loader::IsPregame()) if (Loader::IsPregame())
{ {
MessageBoxA(nullptr, "Registering server commands in pregame state is illegal!", nullptr, MB_ICONERROR); MessageBoxA(nullptr, "Registering server commands in pregame state is illegal!", nullptr, MB_ICONERROR);
#ifdef _DEBUG #ifdef _DEBUG
__debugbreak(); __debugbreak();
#endif #endif
return; return;
} }
@ -120,6 +118,8 @@ namespace Components
{ {
command.append("\n"); // Make sure it's terminated command.append("\n"); // Make sure it's terminated
assert(command.size() < Game::MAX_CMD_LINE);
if (sync) if (sync)
{ {
Game::Cmd_ExecuteSingleCommand(0, 0, command.data()); Game::Cmd_ExecuteSingleCommand(0, 0, command.data());
@ -134,9 +134,9 @@ namespace Components
{ {
auto* cmdFunction = *Game::cmd_functions; 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; return cmdFunction;
} }
@ -174,18 +174,6 @@ namespace Components
} }
} }
bool Command::IsSendingNotifiesDisabled()
{
static std::optional<bool> flag;
if (!flag.has_value())
{
flag.emplace(Flags::HasFlag("disable-notifies"));
}
return flag.value();
}
const std::vector<std::string>& Command::GetExceptions() const std::vector<std::string>& Command::GetExceptions()
{ {
static const auto exceptions = []() -> std::vector<std::string> static const auto exceptions = []() -> std::vector<std::string>
@ -197,7 +185,7 @@ namespace Components
"map", "map",
}; };
if (IsSendingNotifiesDisabled()) if (Flags::HasFlag("disable-notifies"))
{ {
values.emplace_back("vstr"); values.emplace_back("vstr");
values.emplace_back("wait"); values.emplace_back("wait");
@ -219,7 +207,7 @@ namespace Components
const auto& exceptions = GetExceptions(); const auto& exceptions = GetExceptions();
for (const auto& entry : exceptions) for (const auto& entry : exceptions)
{ {
if (!_stricmp(cmd, entry.data())) if (Utils::String::Compare(cmd, entry))
{ {
return false; return false;
} }

View File

@ -73,7 +73,6 @@ namespace Components
static void MainCallback(); static void MainCallback();
static void MainCallbackSV(); static void MainCallbackSV();
static bool IsSendingNotifiesDisabled();
static const std::vector<std::string>& GetExceptions(); static const std::vector<std::string>& GetExceptions();
static bool CL_ShouldSendNotify_Hk(const char* cmd); static bool CL_ShouldSendNotify_Hk(const char* cmd);
}; };

View File

@ -257,7 +257,7 @@ namespace Components
void Dvar::SetFromStringByNameSafeExternal(const char* dvarName, const char* string) void Dvar::SetFromStringByNameSafeExternal(const char* dvarName, const char* string)
{ {
static std::array<const char*, 8> exceptions = static std::array exceptions =
{ {
"ui_showEndOfGame", "ui_showEndOfGame",
"systemlink", "systemlink",

View File

@ -585,6 +585,8 @@ namespace Game
constexpr std::size_t MAX_LOCAL_CLIENTS = 1; constexpr std::size_t MAX_LOCAL_CLIENTS = 1;
constexpr std::size_t MAX_CLIENTS = 18; 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; constexpr auto CMD_MAX_NESTING = 8;
extern CmdArgs* cmd_args; extern CmdArgs* cmd_args;
extern CmdArgs* sv_cmd_args; extern CmdArgs* sv_cmd_args;