fix(rcon): patch vulnerable code

This commit is contained in:
Jack Back 2024-01-15 16:41:53 +01:00
parent 215030f626
commit 6b154a11c5

View File

@ -63,22 +63,20 @@ namespace rcon
std::string build_status_buffer() std::string build_status_buffer()
{ {
const auto sv_maxclients = game::Dvar_FindVar("sv_maxclients"); const auto* sv_maxclients = game::Dvar_FindVar("sv_maxclients");
const auto mapname = game::Dvar_FindVar("mapname"); const auto* mapname = game::Dvar_FindVar("mapname");
std::string buffer{}; std::string buffer{};
buffer.append(utils::string::va("map: %s\n", mapname->current.string)); buffer.append(utils::string::va("map: %s\n", mapname->current.string));
buffer.append( buffer.append("num score bot ping guid name address qport\n");
"num score bot ping guid name address qport\n"); buffer.append("--- ----- --- ---- -------------------------------- ---------------- --------------------- -----\n");
buffer.append(
"--- ----- --- ---- -------------------------------- ---------------- --------------------- -----\n");
for (int i = 0; i < sv_maxclients->current.integer; i++) for (int i = 0; i < sv_maxclients->current.integer; i++)
{ {
const auto client = &game::mp::svs_clients[i]; const auto client = &game::mp::svs_clients[i];
char clean_name[32] = { 0 }; char clean_name[32]{};
strncpy_s(clean_name, client->name, sizeof(clean_name)); strncpy_s(clean_name, client->name, _TRUNCATE);
game::I_CleanStr(clean_name); game::I_CleanStr(clean_name);
if (client->header.state >= 1) if (client->header.state >= 1)
@ -87,11 +85,7 @@ namespace rcon
i, i,
game::G_GetClientScore(i), game::G_GetClientScore(i),
game::SV_BotIsBot(i) ? "Yes" : "No", game::SV_BotIsBot(i) ? "Yes" : "No",
(client->header.state == 2) (client->header.state == 2) ? "CNCT" : (client->header.state == 1) ? "ZMBI" : utils::string::va("%4i", game::SV_GetClientPing(i)),
? "CNCT"
: (client->header.state == 1)
? "ZMBI"
: utils::string::va("%4i", game::SV_GetClientPing(i)),
game::SV_GetGuid(i), game::SV_GetGuid(i),
clean_name, clean_name,
network::net_adr_to_string(client->header.remoteAddress), network::net_adr_to_string(client->header.remoteAddress),
@ -142,8 +136,7 @@ namespace rcon
return; return;
} }
auto status_buffer = build_status_buffer(); console::info("%s", build_status_buffer().data());
console::info(status_buffer.data());
}); });
if (!game::environment::is_dedi()) if (!game::environment::is_dedi())