Blame SOURCES/rabbitmq-c-0.9.0-CVE-2019-18609.patch

5a4435
diff -up rabbitmq-c-0.9.0/librabbitmq/amqp_connection.c.CVE-2019-18609 rabbitmq-c-0.9.0/librabbitmq/amqp_connection.c
5a4435
--- rabbitmq-c-0.9.0/librabbitmq/amqp_connection.c.CVE-2019-18609	2020-04-06 15:10:07.002386201 +0200
5a4435
+++ rabbitmq-c-0.9.0/librabbitmq/amqp_connection.c	2020-04-06 15:17:03.624425371 +0200
5a4435
@@ -287,12 +287,21 @@ int amqp_handle_input(amqp_connection_st
5a4435
     case CONNECTION_STATE_HEADER: {
5a4435
       amqp_channel_t channel;
5a4435
       amqp_pool_t *channel_pool;
5a4435
-      /* frame length is 3 bytes in */
5a4435
+      uint32_t frame_size;
5a4435
+
5a4435
       channel = amqp_d16(amqp_offset(raw_frame, 1));
5a4435
 
5a4435
-      state->target_size =
5a4435
-          amqp_d32(amqp_offset(raw_frame, 3)) + HEADER_SIZE + FOOTER_SIZE;
5a4435
+      /* frame length is 3 bytes in */
5a4435
+      frame_size = amqp_d32(amqp_offset(raw_frame, 3));
5a4435
+      /* To prevent the target_size calculation below from overflowing, check
5a4435
+       * that the stated frame_size is smaller than a signed 32-bit. Given
5a4435
+       * the library only allows configuring frame_max as an int32_t, and
5a4435
+       * frame_size is uint32_t, the math below is safe from overflow. */
5a4435
+      if (frame_size >= INT32_MAX) {
5a4435
+        return AMQP_STATUS_BAD_AMQP_DATA;
5a4435
+      }
5a4435
 
5a4435
+      state->target_size = frame_size + HEADER_SIZE + FOOTER_SIZE;
5a4435
       if ((size_t)state->frame_max < state->target_size) {
5a4435
         return AMQP_STATUS_BAD_AMQP_DATA;
5a4435
       }