Blame SOURCES/httpd-2.4.34-CVE-2021-40438.patch

879b17
diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c
879b17
index fb897a9..38dbb24 100644
879b17
--- a/modules/mappers/mod_rewrite.c
879b17
+++ b/modules/mappers/mod_rewrite.c
879b17
@@ -619,6 +619,13 @@ static unsigned is_absolute_uri(char *uri, int *supportsqs)
879b17
             return 6;
879b17
         }
879b17
         break;
879b17
+
879b17
+    case 'u':
879b17
+    case 'U':
879b17
+        if (!ap_cstr_casecmpn(uri, "nix:", 4)) {        /* unix:     */
879b17
+            *sqs = 1;
879b17
+            return (uri[4] == '/' && uri[5] == '/') ? 7 : 5;
879b17
+        }
879b17
     }
879b17
 
879b17
     return 0;
6af457
diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c
879b17
index d00454e..9685e72 100644
6af457
--- a/modules/proxy/mod_proxy.c
6af457
+++ b/modules/proxy/mod_proxy.c
879b17
@@ -1710,7 +1710,8 @@ PROXY_DECLARE(const char *) ap_proxy_de_socketfy(apr_pool_t *p, const char *url)
6af457
      * the UDS path... ignore it
6af457
      */
6af457
     if (!strncasecmp(url, "unix:", 5) &&
6af457
-        ((ptr = ap_strchr_c(url, '|')) != NULL)) {
6af457
+        ((ptr = ap_strchr_c(url + 5, '|')) != NULL)) {
6af457
+
6af457
         /* move past the 'unix:...|' UDS path info */
6af457
         const char *ret, *c;
6af457
 
6af457
diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c
879b17
index a3999ec..1342cee 100644
6af457
--- a/modules/proxy/proxy_util.c
6af457
+++ b/modules/proxy/proxy_util.c
879b17
@@ -2060,33 +2060,45 @@ static int ap_proxy_retry_worker(const char *proxy_function, proxy_worker *worke
879b17
  * were passed a UDS url (eg: from mod_proxy) and adjust uds_path
879b17
  * as required.  
879b17
  */
879b17
-static void fix_uds_filename(request_rec *r, char **url) 
879b17
+static int fix_uds_filename(request_rec *r, char **url) 
879b17
 {
879b17
-    char *ptr, *ptr2;
879b17
-    if (!r || !r->filename) return;
879b17
+    char *uds_url = r->filename + 6, *origin_url;
6af457
 
6af457
     if (!strncmp(r->filename, "proxy:", 6) &&
6af457
-            (ptr2 = ap_strcasestr(r->filename, "unix:")) &&
6af457
-            (ptr = ap_strchr(ptr2, '|'))) {
879b17
+            !ap_cstr_casecmpn(uds_url, "unix:", 5) &&
879b17
+            (origin_url = ap_strchr(uds_url + 5, '|'))) {
879b17
+        char *uds_path = NULL;
879b17
+        apr_size_t url_len;
6af457
         apr_uri_t urisock;
6af457
         apr_status_t rv;
879b17
-        *ptr = '\0';
879b17
-        rv = apr_uri_parse(r->pool, ptr2, &urisock);
879b17
-        if (rv == APR_SUCCESS) {
879b17
-            char *rurl = ptr+1;
879b17
-            char *sockpath = ap_runtime_dir_relative(r->pool, urisock.path);
879b17
-            apr_table_setn(r->notes, "uds_path", sockpath);
879b17
-            *url = apr_pstrdup(r->pool, rurl); /* so we get the scheme for the uds */
879b17
-            /* r->filename starts w/ "proxy:", so add after that */
879b17
-            memmove(r->filename+6, rurl, strlen(rurl)+1);
879b17
-            ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
879b17
-                    "*: rewrite of url due to UDS(%s): %s (%s)",
879b17
-                    sockpath, *url, r->filename);
879b17
+
879b17
+        *origin_url = '\0';
879b17
+        rv = apr_uri_parse(r->pool, uds_url, &urisock);
879b17
+        *origin_url++ = '|';
879b17
+
879b17
+        if (rv == APR_SUCCESS && urisock.path && (!urisock.hostname
879b17
+                                                  || !urisock.hostname[0])) {
879b17
+             uds_path = ap_runtime_dir_relative(r->pool, urisock.path);
879b17
         }
879b17
-        else {
879b17
-            *ptr = '|';
879b17
+
879b17
+        if (!uds_path) {
879b17
+             ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10292)
879b17
+                     "Invalid proxy UDS filename (%s)", r->filename);
879b17
+             return 0;
879b17
         }
879b17
-    }
879b17
+        apr_table_setn(r->notes, "uds_path", uds_path);
879b17
+
879b17
+        /* Remove the UDS path from *url and r->filename */
879b17
+        url_len = strlen(origin_url);
879b17
+        *url = apr_pstrmemdup(r->pool, origin_url, url_len);
879b17
+        memcpy(uds_url, *url, url_len + 1);
879b17
+
879b17
+        ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
879b17
+                 "*: rewrite of url due to UDS(%s): %s (%s)",
879b17
+                 uds_path, *url, r->filename);
879b17
+     }
879b17
+
879b17
+     return 1;
879b17
 }
879b17
 
879b17
 PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
879b17
@@ -2104,7 +2116,9 @@ PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
879b17
                           "%s: found worker %s for %s",
879b17
                           (*worker)->s->scheme, (*worker)->s->name, *url);
879b17
             *balancer = NULL;
879b17
-            fix_uds_filename(r, url);
879b17
+            if (!fix_uds_filename(r, url)) {
879b17
+                     return HTTP_INTERNAL_SERVER_ERROR;
879b17
+            }
879b17
             access_status = OK;
879b17
         }
879b17
         else if (r->proxyreq == PROXYREQ_PROXY) {
879b17
@@ -2135,7 +2149,9 @@ PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
879b17
                  * regarding the Connection header in the request.
879b17
                  */
879b17
                 apr_table_setn(r->subprocess_env, "proxy-nokeepalive", "1");
879b17
-                fix_uds_filename(r, url);
879b17
+                if (!fix_uds_filename(r, url)) {
879b17
+                     return HTTP_INTERNAL_SERVER_ERROR;
879b17
+                }
879b17
             }
879b17
         }
879b17
     }