Fix memory leak in i2d_ASN1_bio_stream
authorOliver Mihatsch <oliver.mihatsch@virtual-solution.com>
Mon, 12 Apr 2021 14:46:16 +0000 (16:46 +0200)
committerTomas Mraz <tomas@openssl.org>
Fri, 2 Jul 2021 14:17:11 +0000 (16:17 +0200)
commit3a1d2b59522163ebb83bb68e13c896188dc222c6
tree9023a97857ecaec6e5c66b7bb3ae8ea609b1d0f1
parent5cffc49f7213c718ebcc2c1236cdd8c2fae7fb28
Fix memory leak in i2d_ASN1_bio_stream

When creating a signed S/MIME message using SMIME_write_CMS()
if the reading from the bio fails, the state is therefore
still ASN1_STATE_START when BIO_flush() is called by i2d_ASN1_bio_stream().
This results in calling asn1_bio_flush_ex cleanup but will only
reset retry flags as the state is not ASN1_STATE_POST_COPY.
Therefore 48 bytes (Linux x86_64) leaked since the
ndef_prefix_free / ndef_suffix_free callbacks are not executed
and the ndef_aux structure is not freed.

By always calling free function callback in asn1_bio_free() the
memory leak is fixed.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14844)
crypto/asn1/bio_asn1.c
crypto/asn1/bio_ndef.c
test/bio_memleak_test.c