mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-19 20:49:11 +00:00
(svn r14897) -Codechange: don't allow a few command flags to be sent over the network as it's bogus information anyway; e.g. the "do not send over network" flag as it will be set whenever the command is received from the server/client.
-Codechange: test earlier whether the command (send from the server) is actually valid.
This commit is contained in:
@@ -685,6 +685,24 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMMAND)
|
||||
cp->my_cmd = p->Recv_bool();
|
||||
cp->next = NULL;
|
||||
|
||||
if (!IsValidCommand(cp->cmd)) {
|
||||
IConsolePrintF(CC_ERROR, "WARNING: invalid command from server, dropping...");
|
||||
free(cp);
|
||||
return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
if (GetCommandFlags(cp->cmd) & CMD_OFFLINE) {
|
||||
IConsolePrintF(CC_ERROR, "WARNING: offline only command from server, dropping...");
|
||||
free(cp);
|
||||
return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
if ((cp->cmd & CMD_FLAGS_MASK) != 0) {
|
||||
IConsolePrintF(CC_ERROR, "WARNING: invalid command flag from server, dropping...");
|
||||
free(cp);
|
||||
return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
// The server did send us this command..
|
||||
// queue it in our own queue, so we can handle it in the upcoming frame!
|
||||
|
||||
|
@@ -34,6 +34,8 @@ void NetworkAddCommandQueue(NetworkClientSocket *cs, CommandPacket *cp)
|
||||
// Prepare a DoCommand to be send over the network
|
||||
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text)
|
||||
{
|
||||
assert((cmd & CMD_FLAG_MASK) == 0);
|
||||
|
||||
CommandPacket c;
|
||||
|
||||
c.company = _local_company;
|
||||
|
@@ -839,6 +839,11 @@ static bool CheckCommandFlags(const CommandPacket *cp, const NetworkClientInfo *
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((cp->cmd & CMD_FLAGS_MASK) != 0) {
|
||||
IConsolePrintF(CC_ERROR, "WARNING: invalid command flag from client %d (IP: %s), kicking...", ci->client_id, GetClientIP(ci));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user