Skip to content

Commit

Permalink
Fix a possible memory leak in custom_ext_add
Browse files Browse the repository at this point in the history
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #22639)
  • Loading branch information
bernd-edlinger authored and hlandau committed Nov 8, 2023
1 parent 795a1e8 commit bd864f0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ssl/statem/extensions_cust.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ int custom_ext_add(SSL *s, int context, WPACKET *pkt, X509 *x, size_t chainidx,
|| !WPACKET_start_sub_packet_u16(pkt)
|| (outlen > 0 && !WPACKET_memcpy(pkt, out, outlen))
|| !WPACKET_close(pkt)) {
if (meth->free_cb != NULL)
meth->free_cb(s, meth->ext_type, context, out, meth->add_arg);
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
return 0;
}
Expand All @@ -228,6 +230,9 @@ int custom_ext_add(SSL *s, int context, WPACKET *pkt, X509 *x, size_t chainidx,
* We can't send duplicates: code logic should prevent this.
*/
if (!ossl_assert((meth->ext_flags & SSL_EXT_FLAG_SENT) == 0)) {
if (meth->free_cb != NULL)
meth->free_cb(s, meth->ext_type, context, out,
meth->add_arg);
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
return 0;
}
Expand Down

0 comments on commit bd864f0

Please sign in to comment.