Skip to content

Commit

Permalink
Fix null-pointer dereference
Browse files Browse the repository at this point in the history
`upstream_ctx->request` will be NULL in case of redirect errors.
  • Loading branch information
kleisauke committed Mar 15, 2024
1 parent e08f93e commit cff1b06
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/nginx/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ ngx_int_t ngx_weserv_return_error(ngx_http_request_t *r,
ngx_http_arg(r, (u_char *)"errorredirect", 13, &redirect_uri) ==
NGX_OK) {
ngx_str_t parsed_redirect = ngx_null_string;
if (upstream_ctx != nullptr && redirect_uri.len == 1 &&
redirect_uri.data[0] == '1') {
parsed_redirect = upstream_ctx->request->url();
} else {
if (redirect_uri.len != 1 || redirect_uri.data[0] != '1') {
(void)parse_url(r->pool, redirect_uri, &parsed_redirect);
} else if (upstream_ctx != nullptr &&
upstream_ctx->request != nullptr) {
// NB: ->request will be NULL in case of redirect errors.
parsed_redirect = upstream_ctx->request->url();
}

if (parsed_redirect.len > 0 &&
Expand Down

0 comments on commit cff1b06

Please sign in to comment.