Welcome! Log In Create A New Profile

Advanced

[nginx] Fixed alias in regex locations with limit_except/if.

Maxim Dounin
May 16, 2014 10:22AM
details: http://hg.nginx.org/nginx/rev/c985d90a8d1f
branches:
changeset: 5697:c985d90a8d1f
user: Maxim Dounin <mdounin@mdounin.ru>
date: Fri May 16 17:42:24 2014 +0400
description:
Fixed alias in regex locations with limit_except/if.

The ngx_http_map_uri_to_path() function used clcf->regex to detect if
it's working within a location given by a regular expression and have
to replace full URI with alias (instead of a part matching the location
prefix). This is incorrect due to clcf->regex being false in implicit
locations created by if and limit_except.

Fix is to preserve relevant information in clcf->alias instead, by setting
it to NGX_MAX_SIZE_T_VALUE if an alias was specified in a regex location.

diffstat:

src/http/ngx_http_core_module.c | 30 +++++++++++-------------------
1 files changed, 11 insertions(+), 19 deletions(-)

diffs (80 lines):

diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -1245,10 +1245,8 @@ ngx_http_core_try_files_phase(ngx_http_r
if (!alias) {
reserve = len > r->uri.len ? len - r->uri.len : 0;

-#if (NGX_PCRE)
- } else if (clcf->regex) {
+ } else if (alias == NGX_MAX_SIZE_T_VALUE) {
reserve = len;
-#endif

} else {
reserve = len > r->uri.len - alias ? len - (r->uri.len - alias) : 0;
@@ -1365,13 +1363,12 @@ ngx_http_core_try_files_phase(ngx_http_r
if (!alias) {
r->uri = path;

-#if (NGX_PCRE)
- } else if (clcf->regex) {
+ } else if (alias == NGX_MAX_SIZE_T_VALUE) {
if (!test_dir) {
r->uri = path;
r->add_uri_to_alias = 1;
}
-#endif
+
} else {
r->uri.len = alias + path.len;
r->uri.data = ngx_pnalloc(r->pool, r->uri.len);
@@ -2006,16 +2003,12 @@ ngx_http_map_uri_to_path(ngx_http_reques

} else {

-#if (NGX_PCRE)
- ngx_uint_t captures;
-
- captures = alias && clcf->regex;
-
- reserved += captures ? r->add_uri_to_alias ? r->uri.len + 1 : 1
- : r->uri.len - alias + 1;
-#else
- reserved += r->uri.len - alias + 1;
-#endif
+ if (alias == NGX_MAX_SIZE_T_VALUE) {
+ reserved += r->add_uri_to_alias ? r->uri.len + 1 : 1;
+
+ } else {
+ reserved += r->uri.len - alias + 1;
+ }

if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,
clcf->root_values->elts)
@@ -2033,8 +2026,7 @@ ngx_http_map_uri_to_path(ngx_http_reques
*root_length = path->len - reserved;
last = path->data + *root_length;

-#if (NGX_PCRE)
- if (captures) {
+ if (alias == NGX_MAX_SIZE_T_VALUE) {
if (!r->add_uri_to_alias) {
*last = '\0';
return last;
@@ -2042,7 +2034,6 @@ ngx_http_map_uri_to_path(ngx_http_reques

alias = 0;
}
-#endif
}

last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);
@@ -4476,6 +4467,7 @@ ngx_http_core_root(ngx_conf_t *cf, ngx_c

#if (NGX_PCRE)
if (alias && clcf->regex) {
+ clcf->alias = NGX_MAX_SIZE_T_VALUE;
n = 1;
}
#endif

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Fixed alias in regex locations with limit_except/if.

Maxim Dounin 1568 May 16, 2014 10:22AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 124
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready