crypto/http/http_client.c: Add the check for OPENSSL_strdup
authorJiasheng Jiang <jiasheng@iscas.ac.cn>
Wed, 22 Jun 2022 08:41:12 +0000 (16:41 +0800)
committerTomas Mraz <tomas@openssl.org>
Thu, 23 Jun 2022 10:35:09 +0000 (12:35 +0200)
As the potential failure of the OPENSSL_strdup(), it should
be better to check the return value and return error if fails.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18624)

crypto/http/http_client.c

index 790b03fa93967ba44e686b79938e8021b16a6daa..ad7574e69554fedb45a18bf4e86dfa8b7eb16ecf 100644 (file)
@@ -1158,6 +1158,14 @@ BIO *OSSL_HTTP_get(const char *url, const char *proxy, const char *no_proxy,
                 current_url = redirection_url;
                 if (*redirection_url == '/') { /* redirection to same server */
                     path = OPENSSL_strdup(redirection_url);
+                    if (path == NULL) {
+                        OPENSSL_free(host);
+                        OPENSSL_free(port);
+                        (void)OSSL_HTTP_close(rctx, 1);
+                        BIO_free(resp);
+                        OPENSSL_free(current_url);
+                        return NULL;
+                    }
                     goto new_rpath;
                 }
                 OPENSSL_free(host);