mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 23:45:07 -05:00
cmdmon: reply to invalid commands
If an unknown command is received (e.g. from a future client), it should get a reply and print an error code instead of timing out.
This commit is contained in:
13
cmdmon.c
13
cmdmon.c
@@ -1253,14 +1253,7 @@ read_from_cmd_socket(void *anything)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Message size sanity check */
|
if (read_length < offsetof(CMD_Request, data) ||
|
||||||
if (read_length >= offsetof(CMD_Request, data)) {
|
|
||||||
expected_length = PKL_CommandLength(&rx_message);
|
|
||||||
} else {
|
|
||||||
expected_length = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (expected_length < offsetof(CMD_Request, data) ||
|
|
||||||
read_length < offsetof(CMD_Reply, data) ||
|
read_length < offsetof(CMD_Reply, data) ||
|
||||||
rx_message.pkt_type != PKT_TYPE_CMD_REQUEST ||
|
rx_message.pkt_type != PKT_TYPE_CMD_REQUEST ||
|
||||||
rx_message.res1 != 0 ||
|
rx_message.res1 != 0 ||
|
||||||
@@ -1272,6 +1265,7 @@ read_from_cmd_socket(void *anything)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expected_length = PKL_CommandLength(&rx_message);
|
||||||
rx_command = ntohs(rx_message.command);
|
rx_command = ntohs(rx_message.command);
|
||||||
|
|
||||||
tx_message.version = PROTO_VERSION_NUMBER;
|
tx_message.version = PROTO_VERSION_NUMBER;
|
||||||
@@ -1299,7 +1293,8 @@ read_from_cmd_socket(void *anything)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rx_command >= N_REQUEST_TYPES) {
|
if (rx_command >= N_REQUEST_TYPES ||
|
||||||
|
expected_length < (int)offsetof(CMD_Request, data)) {
|
||||||
DEBUG_LOG(LOGF_CmdMon, "Command packet has invalid command %d", rx_command);
|
DEBUG_LOG(LOGF_CmdMon, "Command packet has invalid command %d", rx_command);
|
||||||
|
|
||||||
tx_message.status = htons(STT_INVALID);
|
tx_message.status = htons(STT_INVALID);
|
||||||
|
|||||||
Reference in New Issue
Block a user