]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
OSSL_HTTP_get(): Do not close connection if redirect to same server
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>
Sat, 1 May 2021 17:47:38 +0000 (19:47 +0200)
committerDr. David von Oheimb <dev@ddvo.net>
Fri, 14 May 2021 17:24:42 +0000 (19:24 +0200)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15053)

crypto/http/http_client.c

index f46cc2714fa40914264a42be9a24fe2845f87bf3..50f1e6d378aea411b316d901f26b3ee475d7a918 100644 (file)
@@ -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);