Parcourir la source

This should resolve #223 and #224.

- Buffer length was being calculated incorrectly when check_nrpe sends its
  request.
- There was also a conditional that was missed when printing the final result,
  which would cause a segfault once the buffer length issue was corrected.
madlohe il y a 6 ans
Parent
commit
4529829e00
2 fichiers modifiés avec 11 ajouts et 3 suppressions
  1. 5 0
      CHANGELOG.md
  2. 6 3
      src/check_nrpe.c

+ 5 - 0
CHANGELOG.md

@@ -1,6 +1,11 @@
 NRPE Changelog
 ==============
 
+[4.0.1](https://github.com/NagiosEnterprises/nrpe/releases/tag/nrpe-4.0.1) - 2020-01-22
+---------------------------------------------------------------------------------------
+**FIXES**
+* Fixed syslog flooding with CRC-checking errors when both plugin and agent were updated to version 4 (Sebastian Wolf)
+
 [4.0.0](https://github.com/NagiosEnterprises/nrpe/releases/tag/nrpe-4.0.0) - 2019-01-13
 ---------------------------------------------------------------------------------------
 Note: This update includes security fixes which affect both the check_nrpe plugin and 

+ 6 - 3
src/check_nrpe.c

@@ -1230,7 +1230,9 @@ int send_request()
 		v3_send_packet->packet_version = htons(packet_ver);
 		v3_send_packet->packet_type = htons(QUERY_PACKET);
 		v3_send_packet->alignment = 0;
-		v3_send_packet->buffer_length = htonl(pkt_size - sizeof(v3_packet) + 1);
+		v3_send_packet->buffer_length = pkt_size - sizeof(v3_packet);
+		v3_send_packet->buffer_length += (packet_ver == NRPE_PACKET_VERSION_4 ? NRPE_V4_PACKET_SIZE_OFFSET : NRPE_V3_PACKET_SIZE_OFFSET);
+		v3_send_packet->buffer_length = htonl(v3_send_packet->buffer_length);
 		strcpy(&v3_send_packet->buffer[0], query);
 
 		/* calculate the crc 32 value of the packet */
@@ -1373,7 +1375,7 @@ int read_response()
 
 	/* get the return code from the remote plugin */
 	/* and print the output returned by the daemon */
-	if (packet_ver == NRPE_PACKET_VERSION_3) {
+	if (packet_ver >= NRPE_PACKET_VERSION_3) {
 		result = ntohs(v3_receive_packet->result_code);
 		if (v3_receive_packet->buffer_length == 0) {
 			printf("CHECK_NRPE: No output returned from daemon.\n");
@@ -1612,8 +1614,9 @@ int read_packet(int sock, void *ssl_ptr, v2_packet ** v2_pkt, v3_packet ** v3_pk
 				}
 			}
 			return -1;
-		} else
+		} else {
 			tot_bytes += rc;
+		}
 	}
 #endif