mirror of
https://github.com/nginx/nginx.git
synced 2024-12-12 10:19:00 +08:00
test allocated space as in try_files
This commit is contained in:
parent
6c5c793403
commit
e46f19f7c4
@ -96,7 +96,7 @@ static ngx_int_t
|
|||||||
ngx_http_index_handler(ngx_http_request_t *r)
|
ngx_http_index_handler(ngx_http_request_t *r)
|
||||||
{
|
{
|
||||||
u_char *p, *name;
|
u_char *p, *name;
|
||||||
size_t len, nlen, root, allocated;
|
size_t len, root, reserve, allocated;
|
||||||
ngx_int_t rc;
|
ngx_int_t rc;
|
||||||
ngx_str_t path, uri;
|
ngx_str_t path, uri;
|
||||||
ngx_uint_t i, dir_tested;
|
ngx_uint_t i, dir_tested;
|
||||||
@ -128,6 +128,7 @@ ngx_http_index_handler(ngx_http_request_t *r)
|
|||||||
root = 0;
|
root = 0;
|
||||||
dir_tested = 0;
|
dir_tested = 0;
|
||||||
name = NULL;
|
name = NULL;
|
||||||
|
/* suppress MSVC warning */
|
||||||
path.data = NULL;
|
path.data = NULL;
|
||||||
|
|
||||||
index = ilcf->indices->elts;
|
index = ilcf->indices->elts;
|
||||||
@ -139,8 +140,8 @@ ngx_http_index_handler(ngx_http_request_t *r)
|
|||||||
return ngx_http_internal_redirect(r, &index[i].name, &r->args);
|
return ngx_http_internal_redirect(r, &index[i].name, &r->args);
|
||||||
}
|
}
|
||||||
|
|
||||||
len = ilcf->max_index_len;
|
reserve = ilcf->max_index_len;
|
||||||
nlen = index[i].name.len;
|
len = index[i].name.len;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
|
ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
|
||||||
@ -149,8 +150,7 @@ ngx_http_index_handler(ngx_http_request_t *r)
|
|||||||
e.request = r;
|
e.request = r;
|
||||||
e.flushed = 1;
|
e.flushed = 1;
|
||||||
|
|
||||||
/* 1 byte for terminating '\0' */
|
/* 1 is for terminating '\0' as in static names */
|
||||||
|
|
||||||
len = 1;
|
len = 1;
|
||||||
|
|
||||||
while (*(uintptr_t *) e.ip) {
|
while (*(uintptr_t *) e.ip) {
|
||||||
@ -158,21 +158,19 @@ ngx_http_index_handler(ngx_http_request_t *r)
|
|||||||
len += lcode(&e);
|
len += lcode(&e);
|
||||||
}
|
}
|
||||||
|
|
||||||
nlen = len;
|
|
||||||
|
|
||||||
/* 16 bytes are preallocation */
|
/* 16 bytes are preallocation */
|
||||||
|
|
||||||
len += 16;
|
reserve = len + 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len > (size_t) (path.data + allocated - name)) {
|
if (reserve > allocated) {
|
||||||
|
|
||||||
name = ngx_http_map_uri_to_path(r, &path, &root, len);
|
name = ngx_http_map_uri_to_path(r, &path, &root, reserve);
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
allocated = path.len;
|
allocated = path.data + path.len - name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index[i].values == NULL) {
|
if (index[i].values == NULL) {
|
||||||
@ -193,7 +191,7 @@ ngx_http_index_handler(ngx_http_request_t *r)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (*name == '/') {
|
if (*name == '/') {
|
||||||
uri.len = nlen - 1;
|
uri.len = len - 1;
|
||||||
uri.data = name;
|
uri.data = name;
|
||||||
return ngx_http_internal_redirect(r, &uri, &r->args);
|
return ngx_http_internal_redirect(r, &uri, &r->args);
|
||||||
}
|
}
|
||||||
@ -248,7 +246,7 @@ ngx_http_index_handler(ngx_http_request_t *r)
|
|||||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
uri.len = r->uri.len + nlen - 1;
|
uri.len = r->uri.len + len - 1;
|
||||||
|
|
||||||
if (!clcf->alias) {
|
if (!clcf->alias) {
|
||||||
uri.data = path.data + root;
|
uri.data = path.data + root;
|
||||||
@ -260,7 +258,7 @@ ngx_http_index_handler(ngx_http_request_t *r)
|
|||||||
}
|
}
|
||||||
|
|
||||||
p = ngx_copy(uri.data, r->uri.data, r->uri.len);
|
p = ngx_copy(uri.data, r->uri.data, r->uri.len);
|
||||||
ngx_memcpy(p, name, nlen - 1);
|
ngx_memcpy(p, name, len - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ngx_http_internal_redirect(r, &uri, &r->args);
|
return ngx_http_internal_redirect(r, &uri, &r->args);
|
||||||
@ -491,7 +489,7 @@ ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* include the terminating '\0' to the length to use ngx_copy() */
|
/* include the terminating '\0' to the length to use ngx_memcpy() */
|
||||||
index->name.len++;
|
index->name.len++;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user