Welcome! Log In Create A New Profile

Advanced

[PATCH] Core: fix content handler and location configuration mismatch.

Piotr Sikora
December 06, 2012 08:16PM
Core: fix content handler and location configuration mismatch.

When using exclusive content handlers (proxy_pass, etc.) and "if"
pseudo-locations, content handler was always set to the one from the
last "if" pseudo-location that evaluated to true or to the one from
the location block if "if" pseudo-locations didn't provide any.
At the same time, location configuration was updated for each "if"
pseudo-location that evaluated to true, which resulted in content
handler and location configuration mismatch.

For example, following configuration would result in SIGSEGV, because
"proxy_pass" content handler (set in the "if ($pass)" pseudo-location)
would be called with location configuration from the "if ($slow)"
pseudo-location which doesn't contain any upstream configuration.

location / {
set $pass 1;
set $slow 1;

if ($pass) {
proxy_pass http://127.0.0.1:8000;
}

if ($slow) {
limit_rate 10k;
}
}

This patch fixes this issue by keeping track of and restoring location
configuration from which the content handler originated.

Signed-off-by: Piotr Sikora <piotr@cloudflare.com>
---
src/http/ngx_http_core_module.c | 2 ++
src/http/ngx_http_request.h | 1 +
2 files changed, 3 insertions(+)

diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index faecadd..aec951c 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -1400,6 +1400,7 @@ ngx_http_core_content_phase(ngx_http_request_t *r,
ngx_str_t path;

if (r->content_handler) {
+ r->loc_conf = r->content_handler_loc_conf;
r->write_event_handler = ngx_http_request_empty_handler;
ngx_http_finalize_request(r, r->content_handler(r));
return NGX_OK;
@@ -1526,6 +1527,7 @@ ngx_http_update_location_config(ngx_http_request_t *r)

if (clcf->handler) {
r->content_handler = clcf->handler;
+ r->content_handler_loc_conf = r->loc_conf;
}
}

diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index f234840..97c9607 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -358,6 +358,7 @@ struct ngx_http_request_s {
void **main_conf;
void **srv_conf;
void **loc_conf;
+ void **content_handler_loc_conf;

ngx_http_event_handler_pt read_event_handler;
ngx_http_event_handler_pt write_event_handler;
--
1.8.0.1

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] Core: fix content handler and location configuration mismatch.

Piotr Sikora 1064 December 06, 2012 08:16PM

Re: [PATCH] Core: fix content handler and location configuration mismatch.

Maxim Dounin 438 December 07, 2012 11:28AM

Re: [PATCH] Core: fix content handler and location configuration mismatch.

Piotr Sikora 425 December 09, 2012 02:46AM

Re: [PATCH] Core: fix content handler and location configuration mismatch.

Piotr Sikora 387 December 09, 2012 03:30AM

Re: [PATCH] Core: fix content handler and location configuration mismatch.

Maxim Dounin 421 December 09, 2012 08:04PM

Re: [PATCH] Core: fix content handler and location configuration mismatch.

Piotr Sikora 410 December 11, 2012 04:14AM

Re: [PATCH] Core: fix content handler and location configuration mismatch.

Maxim Dounin 773 December 12, 2012 10:12AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 199
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready