]> git.kaiwu.me - nginx.git/commitdiff
Fixed segfault with try_files introduced by c985d90a8d1f.
authorMaxim Dounin <mdounin@mdounin.ru>
Sun, 16 Aug 2015 07:51:16 +0000 (10:51 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Sun, 16 Aug 2015 07:51:16 +0000 (10:51 +0300)
If alias was used in a location given by a regular expression,
nginx used to do wrong thing in try_files if a location name (i.e.,
regular expression) was an exact prefix of URI.  The following
configuration triggered a segmentation fault on a request to "/mail":

    location ~ /mail {
        alias /path/to/directory;
        try_files $uri =404;
    }

Reported by Per Hansson.

src/http/ngx_http_core_module.c

index d423d8b8074dc3c0d5c31402609b510ea1073c71..8c8d23cd3d308c13f5795cbeeb4b043fbc5cb9d2 100644 (file)
@@ -1239,7 +1239,9 @@ ngx_http_core_try_files_phase(ngx_http_request_t *r,
 
             *e.pos = '\0';
 
-            if (alias && ngx_strncmp(name, clcf->name.data, alias) == 0) {
+            if (alias && alias != NGX_MAX_SIZE_T_VALUE
+                && ngx_strncmp(name, clcf->name.data, alias) == 0)
+            {
                 ngx_memmove(name, name + alias, len - alias);
                 path.len -= alias;
             }