From: Pauli Date: Mon, 21 Jun 2021 00:33:10 +0000 (+1000) Subject: asn1: properly clean up on failed BIO creation X-Git-Tag: openssl-3.0.0-beta2~258 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d65d2963839433bb4f15525df37d0f4f799466e5;p=thirdparty%2Fopenssl.git asn1: properly clean up on failed BIO creation Fixes coverity 1486070 through 1486077 and 1486079 Reviewed-by: Shane Lontis Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/15841) --- diff --git a/crypto/asn1/asn1_parse.c b/crypto/asn1/asn1_parse.c index a131713d737..04d7ef66cfc 100644 --- a/crypto/asn1/asn1_parse.c +++ b/crypto/asn1/asn1_parse.c @@ -27,6 +27,7 @@ static int asn1_print_info(BIO *bp, long offset, int depth, int hl, long len, int pop_f_prefix = 0; long saved_indent = -1; int i = 0; + BIO *bio = NULL; if (constructed & V_ASN1_CONSTRUCTED) p = "cons: "; @@ -43,7 +44,8 @@ static int asn1_print_info(BIO *bp, long offset, int depth, int hl, long len, } if (bp != NULL) { if (BIO_set_prefix(bp, str) <= 0) { - if ((bp = BIO_push(BIO_new(BIO_f_prefix()), bp)) == NULL) + if ((bio = BIO_new(BIO_f_prefix())) == NULL + || (bp = BIO_push(bio, bp)) == NULL) goto err; pop_f_prefix = 1; } @@ -72,10 +74,9 @@ static int asn1_print_info(BIO *bp, long offset, int depth, int hl, long len, err: if (saved_indent >= 0) BIO_set_indent(bp, saved_indent); - if (pop_f_prefix) { + if (pop_f_prefix) BIO_pop(bp); - BIO_free(bp); - } + BIO_free(bio); return i; }