623 if (item == NULL)
624 {
625 frag = dtls1_hm_fragment_new(msg_hdr->msg_len, 1);
626 if ( frag == NULL)
627 goto err;
628 memcpy(&(frag->msg_header), msg_hdr, sizeof(*msg_hdr));
629 frag->msg_header.frag_len = frag->msg_header.msg_len;
630 frag->msg_header.frag_off = 0;
631 }
632 else
633 {
634 frag = (hm_fragment*) item->data;
635 if (frag->msg_header.msg_len != msg_hdr->msg_len)
636 {
637 item = NULL;
638 frag = NULL;
639 goto err;
640 }
641 }
642
643
644 /* If message is already reassembled, this must be a
645 * retransmit and can be dropped. In this case item != NULL and so frag
646 * does not need to be freed.
647 */
648 if (frag->reassembly == NULL)
649 {
650 unsigned char devnull [256];
651
652 while (frag_len)
653 {
654 i = s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE,
655 devnull,
656 frag_len>sizeof(devnull)?sizeof(devnull):frag_len,0);
657 if (i<=0) goto err;
658 frag_len -= i;
659 }
660 return DTLS1_HM_FRAGMENT_RETRY;
661 }
662
663 /* read the body of the fragment (header has already been read */
753 else
754 {
755 if (frag_len != msg_hdr->msg_len)
756 return dtls1_reassemble_fragment(s, msg_hdr, ok);
757
758 if (frag_len > dtls1_max_handshake_message_len(s))
759 goto err;
760
761 frag = dtls1_hm_fragment_new(frag_len, 0);
762 if ( frag == NULL)
763 goto err;
764
765 memcpy(&(frag->msg_header), msg_hdr, sizeof(*msg_hdr));
766
767 if (frag_len)
768 {
769 /* read the body of the fragment (header has already been read */
770 i = s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE,
771 frag->fragment,frag_len,0);
772 if ((unsigned long)i!=frag_len)
773 i = -1;
774 if (i<=0)
775 goto err;
776 }
777
778 item = pitem_new(seq64be, frag);
779 if ( item == NULL)
780 goto err;
781
782 item = pqueue_insert(s->d1->buffered_messages, item);
783 /* pqueue_insert fails iff a duplicate item is inserted.
784 * However, |item| cannot be a duplicate. If it were,
785 * |pqueue_find|, above, would have returned it. Then, either
786 * |frag_len| != |msg_hdr->msg_len| in which case |item| is set
787 * to NULL and it will have been processed with
788 * |dtls1_reassemble_fragment|, above, or the record will have
789 * been discarded. */
790 OPENSSL_assert(item != NULL);
791 }
792
793 return DTLS1_HM_FRAGMENT_RETRY;
|
623 if (item == NULL)
624 {
625 frag = dtls1_hm_fragment_new(msg_hdr->msg_len, 1);
626 if ( frag == NULL)
627 goto err;
628 memcpy(&(frag->msg_header), msg_hdr, sizeof(*msg_hdr));
629 frag->msg_header.frag_len = frag->msg_header.msg_len;
630 frag->msg_header.frag_off = 0;
631 }
632 else
633 {
634 frag = (hm_fragment*) item->data;
635 if (frag->msg_header.msg_len != msg_hdr->msg_len)
636 {
637 item = NULL;
638 frag = NULL;
639 goto err;
640 }
641 }
642
643 /* If message is already reassembled, this must be a
644 * retransmit and can be dropped. In this case item != NULL and so frag
645 * does not need to be freed.
646 */
647 if (frag->reassembly == NULL)
648 {
649 unsigned char devnull [256];
650
651 while (frag_len)
652 {
653 i = s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE,
654 devnull,
655 frag_len>sizeof(devnull)?sizeof(devnull):frag_len,0);
656 if (i<=0) goto err;
657 frag_len -= i;
658 }
659 return DTLS1_HM_FRAGMENT_RETRY;
660 }
661
662 /* read the body of the fragment (header has already been read */
752 else
753 {
754 if (frag_len != msg_hdr->msg_len)
755 return dtls1_reassemble_fragment(s, msg_hdr, ok);
756
757 if (frag_len > dtls1_max_handshake_message_len(s))
758 goto err;
759
760 frag = dtls1_hm_fragment_new(frag_len, 0);
761 if ( frag == NULL)
762 goto err;
763
764 memcpy(&(frag->msg_header), msg_hdr, sizeof(*msg_hdr));
765
766 if (frag_len)
767 {
768 /* read the body of the fragment (header has already been read */
769 i = s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE,
770 frag->fragment,frag_len,0);
771 if ((unsigned long)i!=frag_len)
772 i=-1;
773 if (i<=0)
774 goto err;
775 }
776
777 item = pitem_new(seq64be, frag);
778 if ( item == NULL)
779 goto err;
780
781 item = pqueue_insert(s->d1->buffered_messages, item);
782 /* pqueue_insert fails iff a duplicate item is inserted.
783 * However, |item| cannot be a duplicate. If it were,
784 * |pqueue_find|, above, would have returned it. Then, either
785 * |frag_len| != |msg_hdr->msg_len| in which case |item| is set
786 * to NULL and it will have been processed with
787 * |dtls1_reassemble_fragment|, above, or the record will have
788 * been discarded. */
789 OPENSSL_assert(item != NULL);
790 }
791
792 return DTLS1_HM_FRAGMENT_RETRY;
|