Skip to content

Commit

Permalink
Move freeing of an old record layer to dtls1_clear_sent_buffer
Browse files Browse the repository at this point in the history
When we are clearing the sent messages queue we should ensure we free any
old write record layers that are no longer in use. Previously this logic
was in dtls1_hm_fragment_free() - but this can end up freeing the current
record layer under certain error conditions.

Fixes openssl#22664
  • Loading branch information
mattcaswell committed Nov 9, 2023
1 parent 64f6c07 commit ca1a56a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
11 changes: 11 additions & 0 deletions ssl/d1_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ void dtls1_clear_sent_buffer(SSL_CONNECTION *s)

while ((item = pqueue_pop(s->d1->sent_messages)) != NULL) {
frag = (hm_fragment *)item->data;

if (frag->msg_header.is_ccs
&& frag->msg_header.saved_retransmit_state.wrlmethod != NULL
&& s->rlayer.wrl != frag->msg_header.saved_retransmit_state.wrl) {
/*
* If we're freeing the CCS then we're done with the old wrl and it
* can bee freed
*/
frag->msg_header.saved_retransmit_state.wrlmethod->free(frag->msg_header.saved_retransmit_state.wrl);
}

dtls1_hm_fragment_free(frag);
pitem_free(item);
}
Expand Down
9 changes: 1 addition & 8 deletions ssl/statem/statem_dtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,7 @@ void dtls1_hm_fragment_free(hm_fragment *frag)
{
if (!frag)
return;
if (frag->msg_header.is_ccs) {
/*
* If we're freeing the CCS then we're done with the old wrl and it
* can bee freed
*/
if (frag->msg_header.saved_retransmit_state.wrlmethod != NULL)
frag->msg_header.saved_retransmit_state.wrlmethod->free(frag->msg_header.saved_retransmit_state.wrl);
}

OPENSSL_free(frag->fragment);
OPENSSL_free(frag->reassembly);
OPENSSL_free(frag);
Expand Down

0 comments on commit ca1a56a

Please sign in to comment.