Skip to content

Commit ffbf891

Browse files
committed
mod_proxy: Fix selection of ProxyPassMatch workers with host/port substitution. PR 69233.
With "ProxyPassMatch ^/([^/]+)/(.*)$ https://$1/$2", ap_proxy_get_worker_ex() should not consider the length of scheme://host part of the given URL because of the globbing match on the host part. Fix it by setting worker->s>is_host_matchable when creating a worker with host substitution and avoiding the min_match check in worker_matches() in this case. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1919617 13f79535-47bb-0310-9956-ffa450edef68
1 parent 77d1ba8 commit ffbf891

4 files changed

Lines changed: 22 additions & 14 deletions

File tree

changes-entries/bz69233.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*) mod_proxy: Fix selection of ProxyPassMatch workers with substitution
2+
in the host name or port. PR 69233. [Yann Ylavic]

include/ap_mmn.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,14 +607,15 @@
607607
* and CONN_STATE_PROCESSING
608608
* 20120211.136 (2.4.59-dev) Add wait_io field to struct process_score
609609
* 20120211.137 (2.4.59-dev) Add AP_MPMQ_CAN_WAITIO
610+
* 20120211.138 (2.4.59-dev) Add is_host_matchable to proxy_worker_shared
610611
*/
611612

612613
#define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
613614

614615
#ifndef MODULE_MAGIC_NUMBER_MAJOR
615616
#define MODULE_MAGIC_NUMBER_MAJOR 20120211
616617
#endif
617-
#define MODULE_MAGIC_NUMBER_MINOR 137 /* 0...n */
618+
#define MODULE_MAGIC_NUMBER_MINOR 138 /* 0...n */
618619

619620
/**
620621
* Determine if the server's current MODULE_MAGIC_NUMBER is at least a

modules/proxy/mod_proxy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ typedef struct {
493493
unsigned int address_ttl_set:1;
494494
apr_int32_t address_ttl; /* backend address' TTL (seconds) */
495495
apr_uint32_t address_expiry; /* backend address' next expiry time */
496+
unsigned int is_host_matchable:1;
496497
} proxy_worker_shared;
497498

498499
#define ALIGNED_PROXY_WORKER_SHARED_SIZE (APR_ALIGN_DEFAULT(sizeof(proxy_worker_shared)))

modules/proxy/proxy_util.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,23 +1826,26 @@ static int ap_proxy_strcmp_ematch(const char *str, const char *expected)
18261826
return 0;
18271827
}
18281828

1829-
static APR_INLINE
1830-
int worker_matches(proxy_worker *worker,
1831-
const char *url, apr_size_t url_len,
1832-
apr_size_t min_match, apr_size_t *max_match,
1833-
unsigned int mask)
1829+
static int worker_matches(proxy_worker *worker,
1830+
const char *url, apr_size_t url_len,
1831+
apr_size_t min_match, apr_size_t *max_match,
1832+
unsigned int mask)
18341833
{
18351834
apr_size_t name_len = strlen(worker->s->name_ex);
1836-
int name_match = worker->s->is_name_matchable;
18371835
if (name_len <= url_len
1838-
&& name_len >= min_match
18391836
&& name_len > *max_match
1840-
&& ((name_match
1841-
&& (mask & AP_PROXY_WORKER_IS_MATCH)
1842-
&& !ap_proxy_strcmp_ematch(url, worker->s->name_ex))
1843-
|| (!name_match
1844-
&& (mask & AP_PROXY_WORKER_IS_PREFIX)
1845-
&& !strncmp(url, worker->s->name_ex, name_len)))) {
1837+
/* min_match is the length of the scheme://host part only of url,
1838+
* so it's used as a fast path to avoid the match when url is too
1839+
* small, but it's irrelevant when the worker host contains globs
1840+
* (i.e. ->is_host_matchable).
1841+
*/
1842+
&& (worker->s->is_name_matchable
1843+
? ((mask & AP_PROXY_WORKER_IS_MATCH)
1844+
&& (worker->s->is_host_matchable || name_len >= min_match)
1845+
&& !ap_proxy_strcmp_ematch(url, worker->s->name_ex))
1846+
: ((mask & AP_PROXY_WORKER_IS_PREFIX)
1847+
&& (name_len >= min_match)
1848+
&& !strncmp(url, worker->s->name_ex, name_len)))) {
18461849
*max_match = name_len;
18471850
return 1;
18481851
}
@@ -2132,6 +2135,7 @@ PROXY_DECLARE(char *) ap_proxy_define_worker_ex(apr_pool_t *p,
21322135
wshared->was_malloced = (mask & AP_PROXY_WORKER_IS_MALLOCED) != 0;
21332136
if (mask & AP_PROXY_WORKER_IS_MATCH) {
21342137
wshared->is_name_matchable = 1;
2138+
wshared->is_host_matchable = (address_not_reusable != 0);
21352139

21362140
/* Before AP_PROXY_WORKER_IS_MATCH (< 2.4.47), a regex worker with
21372141
* dollar substitution was never matched against any actual URL, thus

0 commit comments

Comments
 (0)