ASF Bugzilla – Attachment 37932 Details for
Bug 65419
Regexp parsing problem in ProxyPassMatch, Unable to find the relavant path
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Fix ap_proxy_define_worker for matchable workers (v2)
bz_65419-fix_proxy_define_worker-v2.patch (text/plain), 6.44 KB, created by
Yann Ylavic
on 2021-07-02 10:45:51 UTC
(
hide
)
Description:
Fix ap_proxy_define_worker for matchable workers (v2)
Filename:
MIME Type:
Creator:
Yann Ylavic
Created:
2021-07-02 10:45:51 UTC
Size:
6.44 KB
patch
obsolete
>Index: modules/proxy/proxy_util.c >=================================================================== >--- modules/proxy/proxy_util.c (revision 1891137) >+++ modules/proxy/proxy_util.c (working copy) >@@ -19,6 +19,7 @@ > #include "ap_mpm.h" > #include "scoreboard.h" > #include "apr_version.h" >+#include "apr_strings.h" > #include "apr_hash.h" > #include "proxy_util.h" > #include "ajp.h" >@@ -1820,17 +1821,16 @@ PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker( > * shared. This allows for dynamic addition during > * config and runtime. > */ >-PROXY_DECLARE(char *) ap_proxy_define_worker(apr_pool_t *p, >- proxy_worker **worker, >- proxy_balancer *balancer, >- proxy_server_conf *conf, >- const char *url, >- int do_malloc) >+static char *proxy_define_worker(apr_pool_t *p, >+ proxy_worker **worker, >+ proxy_balancer *balancer, >+ proxy_server_conf *conf, const char *url, >+ int do_malloc, int matchable) > { >- int rv; >- apr_uri_t uri, urisock; >+ apr_status_t rv; > proxy_worker_shared *wshared; >- char *ptr, *sockpath = NULL; >+ const char *ptr = NULL, *sockpath = NULL, *pdollars = NULL; >+ apr_uri_t uri; > > /* > * Look to see if we are using UDS: >@@ -1837,20 +1837,58 @@ PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker( > * require format: unix:/path/foo/bar.sock|http://ignored/path2/ > * This results in talking http to the socket at /path/foo/bar.sock > */ >- ptr = ap_strchr((char *)url, '|'); >- if (ptr) { >- *ptr = '\0'; >- rv = apr_uri_parse(p, url, &urisock); >- if (rv == APR_SUCCESS && !ap_cstr_casecmp(urisock.scheme, "unix")) { >- sockpath = ap_runtime_dir_relative(p, urisock.path);; >- url = ptr+1; /* so we get the scheme for the uds */ >+ if (!ap_cstr_casecmp(url, "unix:") && (ptr = ap_strchr_c(url + 5, '|'))) { >+ rv = apr_uri_parse(p, apr_pstrmemdup(p, url, ptr - url), &uri); >+ if (rv == APR_SUCCESS) { >+ sockpath = ap_runtime_dir_relative(p, uri.path);; >+ ptr++; /* so we get the scheme for the uds */ > } > else { >- *ptr = '|'; >+ ptr = url; > } > } >- rv = apr_uri_parse(p, url, &uri); >+ else { >+ ptr = url; >+ } > >+ if (matchable) { >+ /* apr_uri_parse() will accept the '$' sign anywhere in the URL but >+ * in the :port part, and we don't want scheme://host:port$1$2/path >+ * to fail (e.g. "ProxyPassMatch ^/(a|b)(/.*)? http://host:port$2"). >+ * So we trim all the $n from the :port and prepend them in uri.path >+ * afterward for apr_uri_unparse() to restore the original URL below. >+ */ >+#define IS_REF(x) (x[0] == '$' && apr_isdigit(x[1])) >+ const char *pos = ap_strstr_c(ptr, "://"); >+ if (pos) { >+ pos += 3; >+ while (*pos && *pos != ':' && *pos != '/') { >+ pos++; >+ } >+ if (*pos == ':') { >+ pos++; >+ while (*pos && !IS_REF(pos) && *pos != '/') { >+ pos++; >+ } >+ if (IS_REF(pos)) { >+ struct iovec vec[2]; >+ const char *path = pos + 2; >+ while (*path && *path != '/') { >+ path++; >+ } >+ pdollars = apr_pstrmemdup(p, pos, path - pos); >+ vec[0].iov_base = (void *)ptr; >+ vec[0].iov_len = pos - ptr; >+ vec[1].iov_base = (void *)path; >+ vec[1].iov_len = strlen(path); >+ ptr = apr_pstrcatv(p, vec, 2, NULL); >+ } >+ } >+ } >+#undef IS_REF >+ } >+ >+ rv = apr_uri_parse(p, ptr, &uri); > if (rv != APR_SUCCESS) { > return apr_pstrcat(p, "Unable to parse URL: ", url, NULL); > } >@@ -1870,6 +1908,12 @@ PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker( > ap_str_tolower(uri.hostname); > } > ap_str_tolower(uri.scheme); >+ >+ /* Restore/prepend pdollars (if any). */ >+ if (pdollars) { >+ uri.path = apr_pstrcat(p, pdollars, uri.path, NULL); >+ } >+ > /* > * Workers can be associated w/ balancers or on their > * own; ie: the generic reverse-proxy or a worker >@@ -1910,6 +1954,7 @@ PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker( > uri.port = 0; > } > ptr = apr_uri_unparse(p, &uri, APR_URI_UNP_REVEALPASSWORD); >+ > if (PROXY_STRNCPY(wshared->name, ptr) != APR_SUCCESS) { > ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, APLOGNO(02808) > "Alert! worker name (%s) too long; truncated to: %s", ptr, wshared->name); >@@ -1960,6 +2005,16 @@ PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker( > return NULL; > } > >+PROXY_DECLARE(char *) ap_proxy_define_worker(apr_pool_t *p, >+ proxy_worker **worker, >+ proxy_balancer *balancer, >+ proxy_server_conf *conf, >+ const char *url, >+ int do_malloc) >+{ >+ return proxy_define_worker(p, worker, balancer, conf, url, do_malloc, 0); >+} >+ > PROXY_DECLARE(char *) ap_proxy_define_match_worker(apr_pool_t *p, > proxy_worker **worker, > proxy_balancer *balancer, >@@ -1968,18 +2023,14 @@ PROXY_DECLARE(char *) ap_proxy_define_match_worker > int do_malloc) > { > char *err; >- const char *pdollar = ap_strchr_c(url, '$'); > >- if (pdollar != NULL) { >- url = apr_pstrmemdup(p, url, pdollar - url); >- } >- err = ap_proxy_define_worker(p, worker, balancer, conf, url, do_malloc); >+ err = proxy_define_worker(p, worker, balancer, conf, url, do_malloc, 1); > if (err) { > return err; > } > > (*worker)->s->is_name_matchable = 1; >- if (pdollar) { >+ if (ap_strchr_c(url, '$')) { > /* Before ap_proxy_define_match_worker() existed, a regex worker > * with dollar substitution was never matched against the actual > * URL thus the request fell through the generic worker. To avoid
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 65419
:
37931
|
37932
|
37937