diff options
author | Yann Ylavic <ylavic@apache.org> | 2024-07-08 14:35:35 +0200 |
---|---|---|
committer | Yann Ylavic <ylavic@apache.org> | 2024-07-08 14:35:35 +0200 |
commit | 530106b2c1be37f581e269be30a0f2665209995e (patch) | |
tree | 8ebd685b3448a83f4291344851a6c2dd14e5d7f6 /modules | |
parent | fr doc rebuild. (diff) | |
download | apache2-530106b2c1be37f581e269be30a0f2665209995e.tar.xz apache2-530106b2c1be37f581e269be30a0f2665209995e.zip |
mod_proxy: Avoid AH01059 parsing error for SetHandler "unix:" URLs. PR 69160
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).
This can trigger with SetHandler "unix:" URLs which are now also fixed up.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1919015 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'modules')
-rw-r--r-- | modules/proxy/proxy_util.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index f7b78439d1..365f501418 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -2432,7 +2432,7 @@ PROXY_DECLARE(int) ap_proxy_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; + char *uds_path = NULL, *end; apr_uri_t urisock; apr_status_t rv; @@ -2444,9 +2444,10 @@ PROXY_DECLARE(int) ap_proxy_fixup_uds_filename(request_rec *r) || !urisock.hostname[0])) { uds_path = ap_runtime_dir_relative(r->pool, urisock.path); } - if (!uds_path) { + if (!uds_path || !(end = 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"); return HTTP_BAD_REQUEST; } apr_table_setn(r->notes, "uds_path", uds_path); @@ -2455,8 +2456,24 @@ PROXY_DECLARE(int) ap_proxy_fixup_uds_filename(request_rec *r) "*: fixup UDS from %s: %s (%s)", r->filename, origin_url, uds_path); - /* Overwrite the UDS part in place */ - memmove(uds_url, origin_url, strlen(origin_url) + 1); + /* 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). + */ + if (!end[1]) { + r->filename = apr_pstrcat(r->pool, "proxy:", + origin_url, "//localhost", + NULL); + } + else if (end[1] == '/' && end[2] == '/' && !end[3]) { + r->filename = apr_pstrcat(r->pool, "proxy:", + origin_url, "localhost", + NULL); + } + else { + /* Overwrite the UDS part of r->filename in place */ + memmove(uds_url, origin_url, origin_len + 1); + } return OK; } |