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

Maxim Dounin mdounin at mdounin.ru
Wed Dec 12 15:10:55 UTC 2012


Hello!

On Tue, Dec 11, 2012 at 01:12:30AM -0800, Piotr Sikora wrote:

[...]

> --- a/src/http/ngx_http_core_module.c
> +++ b/src/http/ngx_http_core_module.c
> @@ -1400,6 +1400,14 @@ ngx_http_core_content_phase(ngx_http_request_t *r,
>      ngx_str_t  path;
> 
>      if (r->content_handler) {
> +        if (r->loc_conf != r->content_handler_loc_conf) {
> +            ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
> +                          "content handler and configuration mismatch");
> +
> +            ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
> +            return NGX_OK;
> +        }
> +
>          r->write_event_handler = ngx_http_request_empty_handler;
>          ngx_http_finalize_request(r, r->content_handler(r));
>          return NGX_OK;
> @@ -1526,6 +1534,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;
>      }
>  }

As far as I can tell, this will break configs like

    location / {
        proxy_pass http://backend1;

        set $true 1;
        if ($true) {
            proxy_pass http://backend2;
        }

        if ($true) {
            # nothing
        }
    }

which currently works fine.  I mean something like this instead:

--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -636,6 +636,14 @@ ngx_http_upstream_init_request(ngx_http_
 
 found:
 
+    if (uscf == NULL) {
+        ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
+                      "no upstream configuration");
+        ngx_http_upstream_finalize_request(r, u,
+                                           NGX_HTTP_INTERNAL_SERVER_ERROR);
+        return;
+    }
+
     if (uscf->peer.init(r, uscf) != NGX_OK) {
         ngx_http_upstream_finalize_request(r, u,
                                            NGX_HTTP_INTERNAL_SERVER_ERROR);

-- 
Maxim Dounin
http://nginx.com/support.html



More information about the nginx-devel mailing list