From 1d98d4db186e708f059336fb9342d0adb6925e85 Mon Sep 17 00:00:00 2001
From: Eric Covener <covener@apache.org>
Date: Tue, 25 Jun 2024 17:29:32 +0000
Subject: [PATCH] Merge r1918606 from trunk:

validate hostname



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1918607 13f79535-47bb-0310-9956-ffa450edef68
---
 modules/proxy/proxy_util.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Index: apache2-2.4.29/modules/proxy/proxy_util.c
===================================================================
--- apache2-2.4.29.orig/modules/proxy/proxy_util.c
+++ apache2-2.4.29/modules/proxy/proxy_util.c
@@ -2238,6 +2238,13 @@ ap_proxy_determine_connection(apr_pool_t
                              apr_pstrcat(p,"URI cannot be parsed: ", *url,
                                          NULL));
     }
+
+    if (!uri->hostname) {
+        return ap_proxyerror(r, HTTP_BAD_REQUEST,
+                             apr_pstrcat(p,"URI has no hostname: ", *url,
+                                         NULL));
+    }
+
     if (!uri->port) {
         uri->port = ap_proxy_port_of_scheme(uri->scheme);
     }
@@ -3513,6 +3520,10 @@ PROXY_DECLARE(int) ap_proxy_create_hdrbr
      * way. No telling which legacy backend is relying no this.
      */
     if (dconf->preserve_host == 0) {
+        if (!uri->hostname) {
+            rc = HTTP_BAD_REQUEST;
+            goto cleanup;
+        }
         if (ap_strchr_c(uri->hostname, ':')) { /* if literal IPv6 address */
             if (uri->port_str && uri->port != DEFAULT_HTTP_PORT) {
                 buf = apr_pstrcat(p, "Host: [", uri->hostname, "]:",
