]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
cmdmon: reply to invalid commands
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 29 Jan 2016 14:32:47 +0000 (15:32 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 29 Jan 2016 16:55:58 +0000 (17:55 +0100)
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.

cmdmon.c

index 218f7be894163b8095e162324250ca6fd75fa822..61b2e8937ba2d561f93db5ab4aa62adc277d33de 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -1253,14 +1253,7 @@ read_from_cmd_socket(void *anything)
     return;
   }
 
-  /* Message size sanity check */
-  if (read_length >= offsetof(CMD_Request, data)) {
-    expected_length = PKL_CommandLength(&rx_message);
-  } else {
-    expected_length = 0;
-  }
-
-  if (expected_length < offsetof(CMD_Request, data) ||
+  if (read_length < offsetof(CMD_Request, data) ||
       read_length < offsetof(CMD_Reply, data) ||
       rx_message.pkt_type != PKT_TYPE_CMD_REQUEST ||
       rx_message.res1 != 0 ||
@@ -1272,6 +1265,7 @@ read_from_cmd_socket(void *anything)
     return;
   }
 
+  expected_length = PKL_CommandLength(&rx_message);
   rx_command = ntohs(rx_message.command);
 
   tx_message.version = PROTO_VERSION_NUMBER;
@@ -1299,7 +1293,8 @@ read_from_cmd_socket(void *anything)
     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);
 
     tx_message.status = htons(STT_INVALID);