mirror of
https://github.com/nginx/nginx.git
synced 2025-01-21 11:42:59 +08:00
fix segfault if $fastcgi_script_name or $fastcgi_path_info were used before
fastcgi handler, the bug has been introduced in r2444
This commit is contained in:
parent
9aa30bc51e
commit
2da48d32c1
@ -135,8 +135,8 @@ static ngx_int_t ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r,
|
|||||||
ngx_http_variable_value_t *v, uintptr_t data);
|
ngx_http_variable_value_t *v, uintptr_t data);
|
||||||
static ngx_int_t ngx_http_fastcgi_path_info_variable(ngx_http_request_t *r,
|
static ngx_int_t ngx_http_fastcgi_path_info_variable(ngx_http_request_t *r,
|
||||||
ngx_http_variable_value_t *v, uintptr_t data);
|
ngx_http_variable_value_t *v, uintptr_t data);
|
||||||
static ngx_int_t ngx_http_fastcgi_split(ngx_http_request_t *r,
|
static ngx_http_fastcgi_ctx_t *ngx_http_fastcgi_split(ngx_http_request_t *r,
|
||||||
ngx_http_fastcgi_ctx_t *f, ngx_http_fastcgi_loc_conf_t *flcf);
|
ngx_http_fastcgi_loc_conf_t *flcf);
|
||||||
|
|
||||||
static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd,
|
static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||||
void *conf);
|
void *conf);
|
||||||
@ -2111,10 +2111,11 @@ ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r,
|
|||||||
ngx_http_fastcgi_ctx_t *f;
|
ngx_http_fastcgi_ctx_t *f;
|
||||||
ngx_http_fastcgi_loc_conf_t *flcf;
|
ngx_http_fastcgi_loc_conf_t *flcf;
|
||||||
|
|
||||||
f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
|
|
||||||
flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
||||||
|
|
||||||
if (ngx_http_fastcgi_split(r, f, flcf) != NGX_OK) {
|
f = ngx_http_fastcgi_split(r, flcf);
|
||||||
|
|
||||||
|
if (f == NULL) {
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2151,10 +2152,11 @@ ngx_http_fastcgi_path_info_variable(ngx_http_request_t *r,
|
|||||||
ngx_http_fastcgi_ctx_t *f;
|
ngx_http_fastcgi_ctx_t *f;
|
||||||
ngx_http_fastcgi_loc_conf_t *flcf;
|
ngx_http_fastcgi_loc_conf_t *flcf;
|
||||||
|
|
||||||
f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
|
|
||||||
flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
||||||
|
|
||||||
if (ngx_http_fastcgi_split(r, f, flcf) != NGX_OK) {
|
f = ngx_http_fastcgi_split(r, flcf);
|
||||||
|
|
||||||
|
if (f == NULL) {
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2168,35 +2170,46 @@ ngx_http_fastcgi_path_info_variable(ngx_http_request_t *r,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static ngx_int_t
|
static ngx_http_fastcgi_ctx_t *
|
||||||
ngx_http_fastcgi_split(ngx_http_request_t *r, ngx_http_fastcgi_ctx_t *f,
|
ngx_http_fastcgi_split(ngx_http_request_t *r, ngx_http_fastcgi_loc_conf_t *flcf)
|
||||||
ngx_http_fastcgi_loc_conf_t *flcf)
|
|
||||||
{
|
{
|
||||||
|
ngx_http_fastcgi_ctx_t *f;
|
||||||
#if (NGX_PCRE)
|
#if (NGX_PCRE)
|
||||||
ngx_int_t n;
|
ngx_int_t n;
|
||||||
int captures[(1 + 2) * 3];
|
int captures[(1 + 2) * 3];
|
||||||
|
|
||||||
|
f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
|
||||||
|
|
||||||
|
if (f == NULL) {
|
||||||
|
f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t));
|
||||||
|
if (f == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_http_set_ctx(r, f, ngx_http_fastcgi_module);
|
||||||
|
}
|
||||||
|
|
||||||
if (f->script_name.len) {
|
if (f->script_name.len) {
|
||||||
return NGX_OK;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flcf->split_regex == NULL) {
|
if (flcf->split_regex == NULL) {
|
||||||
f->script_name = r->uri;
|
f->script_name = r->uri;
|
||||||
return NGX_OK;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = ngx_regex_exec(flcf->split_regex, &r->uri, captures, (1 + 2) * 3);
|
n = ngx_regex_exec(flcf->split_regex, &r->uri, captures, (1 + 2) * 3);
|
||||||
|
|
||||||
if (n == NGX_REGEX_NO_MATCHED) {
|
if (n == NGX_REGEX_NO_MATCHED) {
|
||||||
f->script_name = r->uri;
|
f->script_name = r->uri;
|
||||||
return NGX_OK;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
||||||
ngx_regex_exec_n " failed: %d on \"%V\" using \"%V\"",
|
ngx_regex_exec_n " failed: %d on \"%V\" using \"%V\"",
|
||||||
n, &r->uri, &flcf->split_name);
|
n, &r->uri, &flcf->split_name);
|
||||||
return NGX_ERROR;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* match */
|
/* match */
|
||||||
@ -2207,13 +2220,24 @@ ngx_http_fastcgi_split(ngx_http_request_t *r, ngx_http_fastcgi_ctx_t *f,
|
|||||||
f->path_info.len = captures[5] - captures[4];
|
f->path_info.len = captures[5] - captures[4];
|
||||||
f->path_info.data = r->uri.data + f->script_name.len;
|
f->path_info.data = r->uri.data + f->script_name.len;
|
||||||
|
|
||||||
return NGX_OK;
|
return f;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
|
||||||
|
|
||||||
|
if (f == NULL) {
|
||||||
|
f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t));
|
||||||
|
if (f == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_http_set_ctx(r, f, ngx_http_fastcgi_module);
|
||||||
|
}
|
||||||
|
|
||||||
f->script_name = r->uri;
|
f->script_name = r->uri;
|
||||||
|
|
||||||
return NGX_OK;
|
return f;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user