]> git.kaiwu.me - nginx.git/commitdiff
fix segfault if no named location are defined, but are used
authorIgor Sysoev <igor@sysoev.ru>
Thu, 11 Dec 2008 17:32:52 +0000 (17:32 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Thu, 11 Dec 2008 17:32:52 +0000 (17:32 +0000)
src/http/ngx_http_core_module.c

index cabb1a17235ed1392fce875cfdc467c3d01eb0f2..8c5e90873fab1aba8aef38d38eaf481331bd8b6e 100644 (file)
@@ -2017,33 +2017,37 @@ ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name)
 
     cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
 
-    for (clcfp = cscf->named_locations; *clcfp; clcfp++) {
+    if (cscf->named_locations) {
 
-        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                       "test location: \"%V\"", &(*clcfp)->name);
+        for (clcfp = cscf->named_locations; *clcfp; clcfp++) {
 
-        if (name->len != (*clcfp)->name.len
-            || ngx_strncmp(name->data, (*clcfp)->name.data, name->len) != 0)
-        {
-            continue;
-        }
+            ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                           "test location: \"%V\"", &(*clcfp)->name);
 
-        ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                       "using location: %V \"%V?%V\"", name, &r->uri, &r->args);
+            if (name->len != (*clcfp)->name.len
+                || ngx_strncmp(name->data, (*clcfp)->name.data, name->len) != 0)
+            {
+                continue;
+            }
 
-        r->internal = 1;
-        r->content_handler = NULL;
-        r->loc_conf = (*clcfp)->loc_conf;
+            ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                           "using location: %V \"%V?%V\"",
+                           name, &r->uri, &r->args);
 
-        ngx_http_update_location_config(r);
+            r->internal = 1;
+            r->content_handler = NULL;
+            r->loc_conf = (*clcfp)->loc_conf;
 
-        cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
+            ngx_http_update_location_config(r);
 
-        r->phase_handler = cmcf->phase_engine.location_rewrite_index;
+            cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
 
-        ngx_http_core_run_phases(r);
+            r->phase_handler = cmcf->phase_engine.location_rewrite_index;
 
-        return NGX_DONE;
+            ngx_http_core_run_phases(r);
+
+            return NGX_DONE;
+        }
     }
 
     ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,