Skip to content

Commit

Permalink
Fix a possible memory leak in ct_move_scts
Browse files Browse the repository at this point in the history
Instead of trying to move the doomed sct back
to the src stack, which may fail as well, simply
free the sct object, as the src list will be
deleted anyway.

Reviewed-by: Paul Yang <kaishen.yy@antfin.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #22762)

(cherry picked from commit a435d78)
  • Loading branch information
bernd-edlinger authored and t8m committed Nov 28, 2023
1 parent 612119b commit 3b61584
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ssl/ssl_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -4981,6 +4981,8 @@ IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER, ssl_cipher_id);
* If |dst| points to a NULL pointer, a new stack will be created and owned by
* the caller.
* Returns the number of SCTs moved, or a negative integer if an error occurs.
* The |dst| stack is created and possibly partially populated even in case
* of error, likewise the |src| stack may be left in an intermediate state.
*/
static int ct_move_scts(STACK_OF(SCT) **dst, STACK_OF(SCT) *src,
sct_source_t origin)
Expand All @@ -5000,15 +5002,14 @@ static int ct_move_scts(STACK_OF(SCT) **dst, STACK_OF(SCT) *src,
if (SCT_set_source(sct, origin) != 1)
goto err;

if (sk_SCT_push(*dst, sct) <= 0)
if (!sk_SCT_push(*dst, sct))
goto err;
scts_moved += 1;
}

return scts_moved;
err:
if (sct != NULL)
sk_SCT_push(src, sct); /* Put the SCT back */
SCT_free(sct);
return -1;
}

Expand Down

0 comments on commit 3b61584

Please sign in to comment.