changeset 1097:df8cdf626c87

fix segfault when $fastcgi_script_name is used in access_log and there was bad request (400)
author Igor Sysoev <igor@sysoev.ru>
date Fri, 09 Feb 2007 11:56:23 +0000
parents 57db008a70ce
children aed9dfe2a4f2
files src/http/modules/ngx_http_fastcgi_module.c
diffstat 1 files changed, 30 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/http/modules/ngx_http_fastcgi_module.c
+++ b/src/http/modules/ngx_http_fastcgi_module.c
@@ -1969,28 +1969,39 @@ ngx_http_fastcgi_script_name_variable(ng
     u_char                       *p;
     ngx_http_fastcgi_loc_conf_t  *flcf;
 
-    v->valid = 1;
-    v->no_cachable = 0;
-    v->not_found = 0;
-
-    flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
-
-    if (r->uri.data[r->uri.len - 1] != '/') {
-        v->len = r->uri.len;
-        v->data = r->uri.data;
+    if (r->uri.len) {
+        v->valid = 1;
+        v->no_cachable = 0;
+        v->not_found = 0;
+
+        flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
+
+        if (r->uri.data[r->uri.len - 1] != '/') {
+            v->len = r->uri.len;
+            v->data = r->uri.data;
+            return NGX_OK;
+        }
+
+        v->len = r->uri.len + flcf->index.len;
+
+        v->data = ngx_palloc(r->pool, v->len);
+        if (v->data == NULL) {
+            return NGX_ERROR;
+        }
+
+        p = ngx_copy(v->data, r->uri.data, r->uri.len);
+        ngx_memcpy(p, flcf->index.data, flcf->index.len);
+
+    } else {
+        v->len = 0;
+        v->valid = 1;
+        v->no_cachable = 0;
+        v->not_found = 0;
+        v->data = NULL;
+
         return NGX_OK;
     }
 
-    v->len = r->uri.len + flcf->index.len;
-
-    v->data = ngx_palloc(r->pool, v->len);
-    if (v->data == NULL) {
-        return NGX_ERROR;
-    }
-
-    p = ngx_copy(v->data, r->uri.data, r->uri.len);
-    ngx_memcpy(p, flcf->index.data, flcf->index.len);
-
     return NGX_OK;
 }