clang / rpms / openssl

Forked from rpms/openssl 2 years ago
Clone
2452420
diff -up openssl-0.9.8k/crypto/pqueue/pqueue.c.dtls-dos openssl-0.9.8k/crypto/pqueue/pqueue.c
2452420
--- openssl-0.9.8k/crypto/pqueue/pqueue.c.dtls-dos	2005-06-28 14:53:33.000000000 +0200
2452420
+++ openssl-0.9.8k/crypto/pqueue/pqueue.c	2009-05-21 18:26:29.000000000 +0200
2452420
@@ -234,3 +234,17 @@ pqueue_next(pitem **item)
2452420
 
2452420
 	return ret;
2452420
 	}
2452420
+
2452420
+int
2452420
+pqueue_size(pqueue_s *pq)
2452420
+{
2452420
+	pitem *item = pq->items;
2452420
+	int count = 0;
2452420
+	
2452420
+	while(item != NULL)
2452420
+	{
2452420
+		count++;
2452420
+		item = item->next;
2452420
+	}
2452420
+	return count;
2452420
+}
2452420
diff -up openssl-0.9.8k/crypto/pqueue/pqueue.h.dtls-dos openssl-0.9.8k/crypto/pqueue/pqueue.h
2452420
--- openssl-0.9.8k/crypto/pqueue/pqueue.h.dtls-dos	2009-04-21 11:43:58.000000000 +0200
2452420
+++ openssl-0.9.8k/crypto/pqueue/pqueue.h	2009-05-21 18:26:29.000000000 +0200
2452420
@@ -91,5 +91,6 @@ pitem *pqueue_iterator(pqueue pq);
2452420
 pitem *pqueue_next(piterator *iter);
2452420
 
2452420
 void   pqueue_print(pqueue pq);
2452420
+int    pqueue_size(pqueue pq);
2452420
 
2452420
 #endif /* ! HEADER_PQUEUE_H */
2452420
diff -up openssl-0.9.8k/ssl/d1_both.c.dtls-dos openssl-0.9.8k/ssl/d1_both.c
2452420
--- openssl-0.9.8k/ssl/d1_both.c.dtls-dos	2007-10-17 23:17:49.000000000 +0200
2452420
+++ openssl-0.9.8k/ssl/d1_both.c	2009-05-21 18:26:29.000000000 +0200
2452420
@@ -519,6 +519,7 @@ dtls1_retrieve_buffered_fragment(SSL *s,
2452420
 
2452420
 	if ( s->d1->handshake_read_seq == frag->msg_header.seq)
2452420
 		{
2452420
+		unsigned long frag_len = frag->msg_header.frag_len;
2452420
 		pqueue_pop(s->d1->buffered_messages);
2452420
 
2452420
 		al=dtls1_preprocess_fragment(s,&frag->msg_header,max);
2452420
@@ -536,7 +537,7 @@ dtls1_retrieve_buffered_fragment(SSL *s,
2452420
 		if (al==0)
2452420
 			{
2452420
 			*ok = 1;
2452420
-			return frag->msg_header.frag_len;
2452420
+			return frag_len;
2452420
 			}
2452420
 
2452420
 		ssl3_send_alert(s,SSL3_AL_FATAL,al);
2452420
@@ -561,7 +562,16 @@ dtls1_process_out_of_seq_message(SSL *s,
2452420
 	if ((msg_hdr->frag_off+frag_len) > msg_hdr->msg_len)
2452420
 		goto err;
2452420
 
2452420
-	if (msg_hdr->seq <= s->d1->handshake_read_seq)
2452420
+	/* Try to find item in queue, to prevent duplicate entries */
2452420
+	pq_64bit_init(&seq64);
2452420
+	pq_64bit_assign_word(&seq64, msg_hdr->seq);
2452420
+	item = pqueue_find(s->d1->buffered_messages, seq64);
2452420
+	pq_64bit_free(&seq64);
2452420
+	
2452420
+	/* Discard the message if sequence number was already there, is
2452420
+	 * too far in the future or the fragment is already in the queue */
2452420
+	if (msg_hdr->seq <= s->d1->handshake_read_seq ||
2452420
+		msg_hdr->seq > s->d1->handshake_read_seq + 10 || item != NULL)
2452420
 		{
2452420
 		unsigned char devnull [256];
2452420
 
2452420
diff -up openssl-0.9.8k/ssl/d1_pkt.c.dtls-dos openssl-0.9.8k/ssl/d1_pkt.c
2452420
--- openssl-0.9.8k/ssl/d1_pkt.c.dtls-dos	2009-04-21 11:44:02.000000000 +0200
2452420
+++ openssl-0.9.8k/ssl/d1_pkt.c	2009-05-21 18:26:29.000000000 +0200
2452420
@@ -167,6 +167,10 @@ dtls1_buffer_record(SSL *s, record_pqueu
2452420
     DTLS1_RECORD_DATA *rdata;
2452420
 	pitem *item;
2452420
 
2452420
+	/* Limit the size of the queue to prevent DOS attacks */
2452420
+	if (pqueue_size(queue->q) >= 100)
2452420
+		return 0;
2452420
+		
2452420
 	rdata = OPENSSL_malloc(sizeof(DTLS1_RECORD_DATA));
2452420
 	item = pitem_new(priority, rdata);
2452420
 	if (rdata == NULL || item == NULL)