Blame SOURCES/openssl-1.0.1e-cve-2015-0206.patch

78ef1d
diff -up openssl-1.0.1e/ssl/d1_pkt.c.dtls-recleak openssl-1.0.1e/ssl/d1_pkt.c
78ef1d
--- openssl-1.0.1e/ssl/d1_pkt.c.dtls-rec-leak	2015-01-13 11:44:12.410022377 +0100
78ef1d
+++ openssl-1.0.1e/ssl/d1_pkt.c	2015-01-13 11:50:40.062789458 +0100
78ef1d
@@ -212,7 +212,7 @@ dtls1_buffer_record(SSL *s, record_pqueu
78ef1d
 	/* Limit the size of the queue to prevent DOS attacks */
78ef1d
 	if (pqueue_size(queue->q) >= 100)
78ef1d
 		return 0;
78ef1d
-		
78ef1d
+
78ef1d
 	rdata = OPENSSL_malloc(sizeof(DTLS1_RECORD_DATA));
78ef1d
 	item = pitem_new(priority, rdata);
78ef1d
 	if (rdata == NULL || item == NULL)
78ef1d
@@ -239,14 +239,6 @@ dtls1_buffer_record(SSL *s, record_pqueu
78ef1d
 	}
78ef1d
 #endif
78ef1d
 
78ef1d
-	/* insert should not fail, since duplicates are dropped */
78ef1d
-	if (pqueue_insert(queue->q, item) == NULL)
78ef1d
-		{
78ef1d
-		OPENSSL_free(rdata);
78ef1d
-		pitem_free(item);
78ef1d
-		return(0);
78ef1d
-		}
78ef1d
-
78ef1d
 	s->packet = NULL;
78ef1d
 	s->packet_length = 0;
78ef1d
 	memset(&(s->s3->rbuf), 0, sizeof(SSL3_BUFFER));
78ef1d
@@ -255,11 +247,24 @@ dtls1_buffer_record(SSL *s, record_pqueu
78ef1d
 	if (!ssl3_setup_buffers(s))
78ef1d
 		{
78ef1d
 		SSLerr(SSL_F_DTLS1_BUFFER_RECORD, ERR_R_INTERNAL_ERROR);
78ef1d
+		if (rdata->rbuf.buf != NULL)
78ef1d
+			OPENSSL_free(rdata->rbuf.buf);
78ef1d
 		OPENSSL_free(rdata);
78ef1d
 		pitem_free(item);
78ef1d
-		return(0);
78ef1d
+		return(-1);
78ef1d
 		}
78ef1d
-	
78ef1d
+
78ef1d
+	/* insert should not fail, since duplicates are dropped */
78ef1d
+	if (pqueue_insert(queue->q, item) == NULL)
78ef1d
+		{
78ef1d
+		SSLerr(SSL_F_DTLS1_BUFFER_RECORD, ERR_R_INTERNAL_ERROR);
78ef1d
+		if (rdata->rbuf.buf != NULL)
78ef1d
+			OPENSSL_free(rdata->rbuf.buf);
78ef1d
+		OPENSSL_free(rdata);
78ef1d
+		pitem_free(item);
78ef1d
+		return(-1);
78ef1d
+		}
78ef1d
+
78ef1d
 	return(1);
78ef1d
 	}
78ef1d
 
78ef1d
@@ -313,8 +318,9 @@ dtls1_process_buffered_records(SSL *s)
78ef1d
             dtls1_get_unprocessed_record(s);
78ef1d
             if ( ! dtls1_process_record(s))
78ef1d
                 return(0);
78ef1d
-            dtls1_buffer_record(s, &(s->d1->processed_rcds), 
78ef1d
-                s->s3->rrec.seq_num);
78ef1d
+            if(dtls1_buffer_record(s, &(s->d1->processed_rcds),
78ef1d
+                s->s3->rrec.seq_num)<0)
78ef1d
+                return -1;
78ef1d
             }
78ef1d
         }
78ef1d
 
78ef1d
@@ -529,7 +535,6 @@ printf("\n");
78ef1d
 
78ef1d
 	/* we have pulled in a full packet so zero things */
78ef1d
 	s->packet_length=0;
78ef1d
-	dtls1_record_bitmap_update(s, &(s->d1->bitmap));/* Mark receipt of record. */
78ef1d
 	return(1);
78ef1d
 
78ef1d
 f_err:
78ef1d
@@ -562,7 +567,8 @@ int dtls1_get_record(SSL *s)
78ef1d
 
78ef1d
 	/* The epoch may have changed.  If so, process all the
78ef1d
 	 * pending records.  This is a non-blocking operation. */
78ef1d
-	dtls1_process_buffered_records(s);
78ef1d
+	if(dtls1_process_buffered_records(s)<0)
78ef1d
+		return -1;
78ef1d
 
78ef1d
 	/* if we're renegotiating, then there may be buffered records */
78ef1d
 	if (dtls1_get_processed_record(s))
78ef1d
@@ -699,7 +705,9 @@ again:
78ef1d
 		{
78ef1d
 		if ((SSL_in_init(s) || s->in_handshake) && !s->d1->listen)
78ef1d
 			{
78ef1d
-			dtls1_buffer_record(s, &(s->d1->unprocessed_rcds), rr->seq_num);
78ef1d
+			if(dtls1_buffer_record(s, &(s->d1->unprocessed_rcds), rr->seq_num)<0)
78ef1d
+				return -1;
78ef1d
+			dtls1_record_bitmap_update(s, bitmap);/* Mark receipt of record. */
78ef1d
 			}
78ef1d
 		rr->length = 0;
78ef1d
 		s->packet_length = 0;
78ef1d
@@ -712,6 +720,7 @@ again:
78ef1d
 		s->packet_length = 0;  /* dump this record */
78ef1d
 		goto again;   /* get another record */
78ef1d
 		}
78ef1d
+	dtls1_record_bitmap_update(s, bitmap);/* Mark receipt of record. */
78ef1d
 
78ef1d
 	return(1);
78ef1d
 
78ef1d
@@ -863,7 +872,11 @@ start:
78ef1d
 		 * buffer the application data for later processing rather
78ef1d
 		 * than dropping the connection.
78ef1d
 		 */
78ef1d
-		dtls1_buffer_record(s, &(s->d1->buffered_app_data), rr->seq_num);
78ef1d
+		if(dtls1_buffer_record(s, &(s->d1->buffered_app_data), rr->seq_num)<0)
78ef1d
+			{
78ef1d
+			SSLerr(SSL_F_DTLS1_READ_BYTES, ERR_R_INTERNAL_ERROR);
78ef1d
+			return -1;
78ef1d
+			}
78ef1d
 		rr->length = 0;
78ef1d
 		goto start;
78ef1d
 		}