]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Reply with status invalid instead of bad length on invalid command
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 19 Jan 2011 13:44:10 +0000 (14:44 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 19 Jan 2011 13:44:10 +0000 (14:44 +0100)
client.c
cmdmon.c

index e6dbd61e4141b922736d1ffb2477587238e3a337..b671bef35ee8a5b6f45899f3909a5e44b35a84fe 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1309,6 +1309,8 @@ submit_request(CMD_Request *request, CMD_Reply *reply, int *reply_auth_ok)
     }
 
     command_length = PKL_CommandLength(request);
+    assert(command_length > 0);
+
 #if 0
     printf("Sent command length=%d bytes\n", command_length);
 #endif
index 38aec8dab85e622dd9c0d7344950c2e8b7fe30f8..9cad3412cb65a98f2596951171f5008d3fbb48c2 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -1784,6 +1784,7 @@ read_from_cmd_socket(void *anything)
 
   read_length = status;
   expected_length = PKL_CommandLength(&rx_message);
+  rx_command = ntohs(rx_message.command);
 
   LCL_ReadRawTime(&now);
   LCL_CookTime(&now, &cooked_now, NULL);
@@ -1858,6 +1859,18 @@ read_from_cmd_socket(void *anything)
     return;
   }
 
+  if (rx_command >= N_REQUEST_TYPES) {
+    if (!LOG_RateLimited()) {
+      LOG(LOGS_WARN, LOGF_CmdMon, "Read command packet with invalid command %d from %s:%hu", rx_command, UTI_IPToString(&remote_ip), remote_port);
+    }
+    if (allowed)
+      CLG_LogCommandAccess(&remote_ip, CLG_CMD_BAD_PKT, cooked_now.tv_sec);
+
+    tx_message.status = htons(STT_INVALID);
+    transmit_reply(&tx_message, &where_from);
+    return;
+  }
+
   if (read_length != expected_length) {
     if (!LOG_RateLimited()) {
       LOG(LOGS_WARN, LOGF_CmdMon, "Read incorrectly sized command packet from %s:%hu", UTI_IPToString(&remote_ip), remote_port);
@@ -1888,8 +1901,6 @@ read_from_cmd_socket(void *anything)
     return;
   }
 
-  rx_command = ntohs(rx_message.command);
-
   /* OK, we have a valid message.  Now dispatch on message type and process it. */
 
   /* Do authentication stuff and command tokens here.  Well-behaved
@@ -2015,10 +2026,9 @@ read_from_cmd_socket(void *anything)
   tx_message.token = htonl(tx_message_token);
 
 
-  /* If command type is invalid, send back reply */
   if (rx_command >= N_REQUEST_TYPES) {
-    tx_message.status = htons(STT_INVALID);
-    tx_message.reply = htons(RPY_NULL);
+    /* This should be already handled */
+    assert(0);
   } else {
     allowed = 0;