From 8801240bc5d5e7fe29b2635bbf9c4d45fd1b2996 Mon Sep 17 00:00:00 2001 From: "Dr. David von Oheimb" Date: Sat, 1 May 2021 19:47:38 +0200 Subject: OSSL_HTTP_get(): Do not close connection if redirect to same server Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/15053) --- crypto/http/http_client.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'crypto/http') diff --git a/crypto/http/http_client.c b/crypto/http/http_client.c index f46cc2714f..50f1e6d378 100644 --- a/crypto/http/http_client.c +++ b/crypto/http/http_client.c @@ -1056,25 +1056,20 @@ BIO *OSSL_HTTP_get(const char *url, const char *proxy, const char *no_proxy, &port, NULL /* port_num */, &path, NULL, NULL)) break; - new_rpath: rctx = OSSL_HTTP_open(host, port, proxy, no_proxy, use_ssl, bio, rbio, bio_update_fn, arg, buf_size, max_resp_len, timeout); + new_rpath: if (rctx != NULL) { if (!OSSL_HTTP_set_request(rctx, path, headers, NULL /* content_type */, NULL /* req_mem */, expected_ct, expect_asn1, -1 /* use same max time */, - 0 /* no keep_alive */)) { + 0 /* no keep_alive */)) OSSL_HTTP_REQ_CTX_free(rctx); - } else { + else resp = OSSL_HTTP_exchange(rctx, &redirection_url); - if (!OSSL_HTTP_close(rctx, resp != NULL)) { - BIO_free(resp); - resp = NULL; - } - } } OPENSSL_free(path); if (resp == NULL && redirection_url != NULL) { @@ -1088,12 +1083,18 @@ BIO *OSSL_HTTP_get(const char *url, const char *proxy, const char *no_proxy, } OPENSSL_free(host); OPENSSL_free(port); + (void)OSSL_HTTP_close(rctx, 1); continue; } + /* if redirection not allowed, ignore it */ OPENSSL_free(redirection_url); } OPENSSL_free(host); OPENSSL_free(port); + if (!OSSL_HTTP_close(rctx, resp != NULL)) { + BIO_free(resp); + resp = NULL; + } break; } OPENSSL_free(current_url); -- cgit v1.2.3