[nginx] svn commit: r4965 - trunk/src/http

mdounin at mdounin.ru mdounin at mdounin.ru
Thu Dec 13 16:06:00 UTC 2012


Author: mdounin
Date: 2012-12-13 16:05:59 +0000 (Thu, 13 Dec 2012)
New Revision: 4965
URL: http://trac.nginx.org/nginx/changeset/4965/nginx

Log:
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:
   trunk/src/http/ngx_http_upstream.c

Modified: trunk/src/http/ngx_http_upstream.c
===================================================================
--- trunk/src/http/ngx_http_upstream.c	2012-12-13 15:05:19 UTC (rev 4964)
+++ trunk/src/http/ngx_http_upstream.c	2012-12-13 16:05:59 UTC (rev 4965)
@@ -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