diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2022-01-03 17:03:13 +0100 |
---|---|---|
committer | Dr. David von Oheimb <dev@ddvo.net> | 2022-01-04 17:03:11 +0100 |
commit | c245cc1be1acb47b1f983dea3bbb0caf36a33712 (patch) | |
tree | ab86a8780aa3949fb5f45f6758c9dcab1ddadebe /apps | |
parent | 46ee414f64a846a6a7606b1fba47a084dea172eb (diff) |
app_http_tls_cb: Fix double-free in case TLS not used
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17400)
(cherry picked from commit 97b8c859c64bc60fcf5bb27ed51489c81fde41b3)
Diffstat (limited to 'apps')
-rw-r--r-- | apps/lib/apps.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/apps/lib/apps.c b/apps/lib/apps.c index 2d3641ea8e..25a6b6bcc3 100644 --- a/apps/lib/apps.c +++ b/apps/lib/apps.c @@ -2444,9 +2444,10 @@ static const char *tls_error_hint(void) /* HTTP callback function that supports TLS connection also via HTTPS proxy */ BIO *app_http_tls_cb(BIO *bio, void *arg, int connect, int detail) { + APP_HTTP_TLS_INFO *info = (APP_HTTP_TLS_INFO *)arg; + SSL_CTX *ssl_ctx = info->ssl_ctx; + if (connect && detail) { /* connecting with TLS */ - APP_HTTP_TLS_INFO *info = (APP_HTTP_TLS_INFO *)arg; - SSL_CTX *ssl_ctx = info->ssl_ctx; SSL *ssl; BIO *sbio = NULL; @@ -2480,12 +2481,14 @@ BIO *app_http_tls_cb(BIO *bio, void *arg, int connect, int detail) if (hint != NULL) ERR_add_error_data(2, " : ", hint); } - (void)ERR_set_mark(); - BIO_ssl_shutdown(bio); - cbio = BIO_pop(bio); /* connect+HTTP BIO */ - BIO_free(bio); /* SSL BIO */ - (void)ERR_pop_to_mark(); /* hide SSL_R_READ_BIO_NOT_SET etc. */ - bio = cbio; + if (ssl_ctx != NULL) { + (void)ERR_set_mark(); + BIO_ssl_shutdown(bio); + cbio = BIO_pop(bio); /* connect+HTTP BIO */ + BIO_free(bio); /* SSL BIO */ + (void)ERR_pop_to_mark(); /* hide SSL_R_READ_BIO_NOT_SET etc. */ + bio = cbio; + } } return bio; } |