Check msg size in command handling

This commit is contained in:
Federico Cecchetto 2022-03-10 22:12:56 +01:00
parent f589892589
commit 26eeea68e9
2 changed files with 3 additions and 3 deletions

View File

@ -121,7 +121,7 @@ namespace auth
const auto offset = sizeof("connect") + 4;
proto::network::connect_info info;
if (!info.ParseFromArray(msg->data + offset, msg->cursize - offset))
if (msg->cursize < offset || !info.ParseFromArray(msg->data + offset, msg->cursize - offset))
{
network::send(*from, "error", "Invalid connect data!", '\n');
return;

View File

@ -24,12 +24,12 @@ namespace network
const auto cmd_string = utils::string::to_lower(command);
auto& callbacks = get_callbacks();
const auto handler = callbacks.find(cmd_string);
if (handler == callbacks.end())
const auto offset = cmd_string.size() + 5;
if (message->cursize < offset || handler == callbacks.end())
{
return false;
}
const auto offset = cmd_string.size() + 5;
const std::string_view data(message->data + offset, message->cursize - offset);
handler->second(*address, data);