Mercurial > hg > nginx-quic
comparison src/http/ngx_http_core_module.c @ 5697:c985d90a8d1f
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.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 16 May 2014 17:42:24 +0400 |
parents | b51bd021808b |
children | 790ba7484bb6 |
comparison
equal
deleted
inserted
replaced
5696:19a14a484707 | 5697:c985d90a8d1f |
---|---|
1243 } | 1243 } |
1244 | 1244 |
1245 if (!alias) { | 1245 if (!alias) { |
1246 reserve = len > r->uri.len ? len - r->uri.len : 0; | 1246 reserve = len > r->uri.len ? len - r->uri.len : 0; |
1247 | 1247 |
1248 #if (NGX_PCRE) | 1248 } else if (alias == NGX_MAX_SIZE_T_VALUE) { |
1249 } else if (clcf->regex) { | |
1250 reserve = len; | 1249 reserve = len; |
1251 #endif | |
1252 | 1250 |
1253 } else { | 1251 } else { |
1254 reserve = len > r->uri.len - alias ? len - (r->uri.len - alias) : 0; | 1252 reserve = len > r->uri.len - alias ? len - (r->uri.len - alias) : 0; |
1255 } | 1253 } |
1256 | 1254 |
1363 path.data += root; | 1361 path.data += root; |
1364 | 1362 |
1365 if (!alias) { | 1363 if (!alias) { |
1366 r->uri = path; | 1364 r->uri = path; |
1367 | 1365 |
1368 #if (NGX_PCRE) | 1366 } else if (alias == NGX_MAX_SIZE_T_VALUE) { |
1369 } else if (clcf->regex) { | |
1370 if (!test_dir) { | 1367 if (!test_dir) { |
1371 r->uri = path; | 1368 r->uri = path; |
1372 r->add_uri_to_alias = 1; | 1369 r->add_uri_to_alias = 1; |
1373 } | 1370 } |
1374 #endif | 1371 |
1375 } else { | 1372 } else { |
1376 r->uri.len = alias + path.len; | 1373 r->uri.len = alias + path.len; |
1377 r->uri.data = ngx_pnalloc(r->pool, r->uri.len); | 1374 r->uri.data = ngx_pnalloc(r->pool, r->uri.len); |
1378 if (r->uri.data == NULL) { | 1375 if (r->uri.data == NULL) { |
1379 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 1376 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
2004 | 2001 |
2005 last = ngx_copy(path->data, clcf->root.data, clcf->root.len); | 2002 last = ngx_copy(path->data, clcf->root.data, clcf->root.len); |
2006 | 2003 |
2007 } else { | 2004 } else { |
2008 | 2005 |
2009 #if (NGX_PCRE) | 2006 if (alias == NGX_MAX_SIZE_T_VALUE) { |
2010 ngx_uint_t captures; | 2007 reserved += r->add_uri_to_alias ? r->uri.len + 1 : 1; |
2011 | 2008 |
2012 captures = alias && clcf->regex; | 2009 } else { |
2013 | 2010 reserved += r->uri.len - alias + 1; |
2014 reserved += captures ? r->add_uri_to_alias ? r->uri.len + 1 : 1 | 2011 } |
2015 : r->uri.len - alias + 1; | |
2016 #else | |
2017 reserved += r->uri.len - alias + 1; | |
2018 #endif | |
2019 | 2012 |
2020 if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved, | 2013 if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved, |
2021 clcf->root_values->elts) | 2014 clcf->root_values->elts) |
2022 == NULL) | 2015 == NULL) |
2023 { | 2016 { |
2031 } | 2024 } |
2032 | 2025 |
2033 *root_length = path->len - reserved; | 2026 *root_length = path->len - reserved; |
2034 last = path->data + *root_length; | 2027 last = path->data + *root_length; |
2035 | 2028 |
2036 #if (NGX_PCRE) | 2029 if (alias == NGX_MAX_SIZE_T_VALUE) { |
2037 if (captures) { | |
2038 if (!r->add_uri_to_alias) { | 2030 if (!r->add_uri_to_alias) { |
2039 *last = '\0'; | 2031 *last = '\0'; |
2040 return last; | 2032 return last; |
2041 } | 2033 } |
2042 | 2034 |
2043 alias = 0; | 2035 alias = 0; |
2044 } | 2036 } |
2045 #endif | |
2046 } | 2037 } |
2047 | 2038 |
2048 last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1); | 2039 last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1); |
2049 | 2040 |
2050 return last; | 2041 return last; |
4474 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | 4465 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); |
4475 sc.variables = n; | 4466 sc.variables = n; |
4476 | 4467 |
4477 #if (NGX_PCRE) | 4468 #if (NGX_PCRE) |
4478 if (alias && clcf->regex) { | 4469 if (alias && clcf->regex) { |
4470 clcf->alias = NGX_MAX_SIZE_T_VALUE; | |
4479 n = 1; | 4471 n = 1; |
4480 } | 4472 } |
4481 #endif | 4473 #endif |
4482 | 4474 |
4483 if (n) { | 4475 if (n) { |