Skip to content

Commit 4e0fbdc

Browse files
aglmattcaswell
authored andcommitted
Remove some duplicate DTLS code.
In a couple of functions, a sequence number would be calculated twice. Additionally, in |dtls1_process_out_of_seq_message|, we know that |frag_len| <= |msg_hdr->msg_len| so the later tests for |frag_len < msg_hdr->msg_len| can be more clearly written as |frag_len != msg_hdr->msg_len|, since that's the only remaining case. Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Emilia Käsper <emilia@openssl.org>
1 parent 0c37aed commit 4e0fbdc

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

ssl/d1_both.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ static unsigned long dtls1_max_handshake_message_len(const SSL *s)
599599
}
600600

601601
static int
602-
dtls1_reassemble_fragment(SSL *s, struct hm_header_st* msg_hdr, int *ok)
602+
dtls1_reassemble_fragment(SSL *s, const struct hm_header_st* msg_hdr, int *ok)
603603
{
604604
hm_fragment *frag = NULL;
605605
pitem *item = NULL;
@@ -682,10 +682,6 @@ dtls1_reassemble_fragment(SSL *s, struct hm_header_st* msg_hdr, int *ok)
682682

683683
if (item == NULL)
684684
{
685-
memset(seq64be,0,sizeof(seq64be));
686-
seq64be[6] = (unsigned char)(msg_hdr->seq>>8);
687-
seq64be[7] = (unsigned char)(msg_hdr->seq);
688-
689685
item = pitem_new(seq64be, frag);
690686
if (item == NULL)
691687
{
@@ -711,7 +707,7 @@ dtls1_reassemble_fragment(SSL *s, struct hm_header_st* msg_hdr, int *ok)
711707

712708

713709
static int
714-
dtls1_process_out_of_seq_message(SSL *s, struct hm_header_st* msg_hdr, int *ok)
710+
dtls1_process_out_of_seq_message(SSL *s, const struct hm_header_st* msg_hdr, int *ok)
715711
{
716712
int i=-1;
717713
hm_fragment *frag = NULL;
@@ -731,7 +727,7 @@ dtls1_process_out_of_seq_message(SSL *s, struct hm_header_st* msg_hdr, int *ok)
731727
/* If we already have an entry and this one is a fragment,
732728
* don't discard it and rather try to reassemble it.
733729
*/
734-
if (item != NULL && frag_len < msg_hdr->msg_len)
730+
if (item != NULL && frag_len != msg_hdr->msg_len)
735731
item = NULL;
736732

737733
/* Discard the message if sequence number was already there, is
@@ -756,7 +752,7 @@ dtls1_process_out_of_seq_message(SSL *s, struct hm_header_st* msg_hdr, int *ok)
756752
}
757753
else
758754
{
759-
if (frag_len < msg_hdr->msg_len)
755+
if (frag_len != msg_hdr->msg_len)
760756
return dtls1_reassemble_fragment(s, msg_hdr, ok);
761757

762758
if (frag_len > dtls1_max_handshake_message_len(s))
@@ -779,10 +775,6 @@ dtls1_process_out_of_seq_message(SSL *s, struct hm_header_st* msg_hdr, int *ok)
779775
goto err;
780776
}
781777

782-
memset(seq64be,0,sizeof(seq64be));
783-
seq64be[6] = (unsigned char)(msg_hdr->seq>>8);
784-
seq64be[7] = (unsigned char)(msg_hdr->seq);
785-
786778
item = pitem_new(seq64be, frag);
787779
if ( item == NULL)
788780
goto err;

0 commit comments

Comments
 (0)