[nginx] svn commit: r5045 - in branches/stable-1.2: . src/http

mdounin at mdounin.ru mdounin at mdounin.ru
Sun Feb 10 03:27:16 UTC 2013


Author: mdounin
Date: 2013-02-10 03:27:15 +0000 (Sun, 10 Feb 2013)
New Revision: 5045
URL: http://trac.nginx.org/nginx/changeset/5045/nginx

Log:
Merge of r4965: upstream: fixed SIGSEGV with the "if" directive.

Configuration like

    location / {
        set $true 1;

        if ($true) {
            proxy_pass http://backend;
        }

        if ($true) {
            # nothing
        }
    }

resulted in segmentation fault due to NULL pointer dereference as the
upstream configuration wasn't initialized in an implicit location created
by the last if(), but the r->content_handler was set due to first if().

Instead of committing a suicide by dereferencing a NULL pointer, return
500 (Internal Server Error) in such cases, i.e. if uscf is NULL.  Better
fix would be to avoid such cases by fixing the "if" directive handling,
but it's out of scope of this patch.

Prodded by Piotr Sikora.


Modified:
   branches/stable-1.2/
   branches/stable-1.2/src/http/ngx_http_upstream.c

Index: branches/stable-1.2
===================================================================
--- branches/stable-1.2	2013-02-10 03:22:58 UTC (rev 5044)
+++ branches/stable-1.2	2013-02-10 03:27:15 UTC (rev 5045)

Property changes on: branches/stable-1.2
___________________________________________________________________
Modified: svn:mergeinfo
## -1 +1 ##
-/trunk:4611-4632,4636-4657,4671-4672,4674-4676,4682,4684-4699,4704-4706,4713,4736-4741,4754,4756-4771,4775,4777-4780,4782-4785,4795,4811-4820,4822-4824,4828-4835,4840-4844,4865-4872,4885-4887,4890-4896,4913-4925,4933-4934,4939,4944-4949,4961-4964,4973,4978,4984,5011
+/trunk:4611-4632,4636-4657,4671-4672,4674-4676,4682,4684-4699,4704-4706,4713,4736-4741,4754,4756-4771,4775,4777-4780,4782-4785,4795,4811-4820,4822-4824,4828-4835,4840-4844,4865-4872,4885-4887,4890-4896,4913-4925,4933-4934,4939,4944-4949,4961-4965,4973,4978,4984,5011
\ No newline at end of property
Modified: branches/stable-1.2/src/http/ngx_http_upstream.c
===================================================================
--- branches/stable-1.2/src/http/ngx_http_upstream.c	2013-02-10 03:22:58 UTC (rev 5044)
+++ branches/stable-1.2/src/http/ngx_http_upstream.c	2013-02-10 03:27:15 UTC (rev 5045)
@@ -636,6 +636,14 @@
 
 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);



More information about the nginx-devel mailing list