]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
*) mod_proxy: Avoid AH01059 parsing error for SetHandler "unix:" URLs
authorYann Ylavic <ylavic@apache.org>
Fri, 26 Jul 2024 14:36:25 +0000 (14:36 +0000)
committerYann Ylavic <ylavic@apache.org>
Fri, 26 Jul 2024 14:36:25 +0000 (14:36 +0000)
   in <Location> (incomplete fix in 2.4.62). PR 69160.

When SetHandler "unix:..." is used in a <Location "/path"> block, the path
gets appended (including $DOCUMENT_ROOT somehow) to r->filename hence the
current checks in fixup_uds_filename() to add "localhost" when missing don't
work. Fix them.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1919532 13f79535-47bb-0310-9956-ffa450edef68

changes-entries/pr69160-again.txt [new file with mode: 0644]
modules/proxy/proxy_util.c

diff --git a/changes-entries/pr69160-again.txt b/changes-entries/pr69160-again.txt
new file mode 100644 (file)
index 0000000..067b10a
--- /dev/null
@@ -0,0 +1,2 @@
+  *) mod_proxy: Avoid AH01059 parsing error for SetHandler "unix:" URLs
+     in <Location> (incomplete fix in 2.4.62). PR 69160. [Yann Ylavic]
index cbc31104c37bf59c7d05c718c3579419e8e06dc3..ae964eb930f9d1e6e7e939cdcac93085c8078f4b 100644 (file)
@@ -2432,7 +2432,7 @@ static int fixup_uds_filename(request_rec *r)
     if (!strncmp(r->filename, "proxy:", 6) &&
             !ap_cstr_casecmpn(uds_url, "unix:", 5) &&
             (origin_url = ap_strchr(uds_url + 5, '|'))) {
-        char *uds_path = NULL, *end;
+        char *uds_path = NULL, *col;
         apr_uri_t urisock;
         apr_status_t rv;
 
@@ -2444,7 +2444,7 @@ static int fixup_uds_filename(request_rec *r)
                                                   || !urisock.hostname[0])) {
             uds_path = ap_runtime_dir_relative(r->pool, urisock.path);
         }
-        if (!uds_path || !(end = ap_strchr(origin_url, ':'))) {
+        if (!uds_path || !(col = ap_strchr(origin_url, ':'))) {
             ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10292)
                     "Invalid proxy UDS filename (%s)", r->filename);
             apr_table_unset(r->notes, "uds_path");
@@ -2457,21 +2457,39 @@ static int fixup_uds_filename(request_rec *r)
                 r->filename, origin_url, uds_path);
 
         /* The hostname part of the URL is not mandated for UDS though
-         * the canon_handler hooks will require it, so add "localhost"
-         * if it's missing (won't be used anyway for an AF_UNIX socket).
+         * the canon_handler hooks will require it. ProxyPass URLs are
+         * fixed at load time by adding "localhost" automatically in the
+         * worker URL, but SetHandler "proxy:unix:/udspath|scheme:[//]"
+         * URLs are not so we have to fix it here the same way.
          */
-        if (!end[1]) {
+        if (!col[1]) {
+            /* origin_url is "scheme:" */
             r->filename = apr_pstrcat(r->pool, "proxy:",
                                       origin_url, "//localhost",
                                       NULL);
         }
-        else if (end[1] == '/' && end[2] == '/' && !end[3]) {
+        /* For a SetHandler "proxy:..." in a <Location "/path">, the "/path"
+         * is appended to r->filename, hence the below origin_url cases too:
+         */
+        else if (col[1] == '/' && (col[2] != '/'    /* "scheme:/path" */
+                                   || col[3] == '/' /* "scheme:///path" */
+                                   || !col[3])) {   /* "scheme://" */
+            char *scheme = origin_url;
+            *col = '\0'; /* nul terminate scheme */
+            if (col[2] != '/') {
+                origin_url = col + 1;
+            }
+            else {
+                origin_url = col + 3;
+            }
             r->filename = apr_pstrcat(r->pool, "proxy:",
-                                      origin_url, "localhost",
-                                      NULL);
+                                      scheme, "://localhost",
+                                      origin_url, NULL);
         }
         else {
-            /* Overwrite the UDS part of r->filename in place */
+            /* origin_url is normal "scheme://host/path", can overwrite
+             * the UDS part of r->filename in place.
+             */
             memmove(uds_url, origin_url, strlen(origin_url) + 1);
         }
         return OK;