Skip to content

Commit 759328e

Browse files
committed
server: fix out-of-range substring call in OOB handling
1 parent be64bf1 commit 759328e

File tree

1 file changed

+40
-28
lines changed

1 file changed

+40
-28
lines changed

code/components/citizen-server-impl/src/GameServer.cpp

+40-28
Original file line numberDiff line numberDiff line change
@@ -846,43 +846,55 @@ namespace fx
846846

847847
gscomms_execute_callback_on_main_thread([=]()
848848
{
849-
int spacePos = data.find_first_of(" \n");
849+
try
850+
{
851+
int spacePos = data.find_first_of(" \n");
850852

851-
auto password = data.substr(0, spacePos);
852-
auto command = data.substr(spacePos);
853+
if (spacePos == std::string::npos)
854+
{
855+
return;
856+
}
853857

854-
auto serverPassword = server->GetRconPassword();
858+
auto password = data.substr(0, spacePos);
859+
auto command = data.substr(spacePos);
855860

856-
std::string printString;
861+
auto serverPassword = server->GetRconPassword();
857862

858-
PrintListenerContext context([&](const std::string_view& print)
859-
{
860-
printString += print;
861-
});
863+
std::string printString;
862864

863-
ScopeDestructor destructor([&]()
864-
{
865-
server->SendOutOfBand(from, "print " + printString);
866-
});
865+
PrintListenerContext context([&](const std::string_view& print)
866+
{
867+
printString += print;
868+
});
867869

868-
if (serverPassword.empty())
869-
{
870-
trace("The server must set rcon_password to be able to use this command.\n");
871-
return;
872-
}
870+
ScopeDestructor destructor([&]()
871+
{
872+
server->SendOutOfBand(from, "print " + printString);
873+
});
873874

874-
if (password != serverPassword)
875-
{
876-
trace("Invalid password.\n");
877-
return;
878-
}
875+
if (serverPassword.empty())
876+
{
877+
trace("The server must set rcon_password to be able to use this command.\n");
878+
return;
879+
}
879880

880-
auto ctx = server->GetInstance()->GetComponent<console::Context>();
881-
ctx->ExecuteBuffer();
881+
if (password != serverPassword)
882+
{
883+
trace("Invalid password.\n");
884+
return;
885+
}
886+
887+
auto ctx = server->GetInstance()->GetComponent<console::Context>();
888+
ctx->ExecuteBuffer();
889+
890+
se::ScopedPrincipal principalScope(se::Principal{ "system.console" });
891+
ctx->AddToBuffer(std::string(command));
892+
ctx->ExecuteBuffer();
893+
}
894+
catch (std::exception& e)
895+
{
882896

883-
se::ScopedPrincipal principalScope(se::Principal{ "system.console" });
884-
ctx->AddToBuffer(std::string(command));
885-
ctx->ExecuteBuffer();
897+
}
886898
});
887899
}
888900

0 commit comments

Comments
 (0)