comparison src/http/ngx_http_upstream.c @ 4964:2464ccebdb52

Upstream: fixed SIGSEGV with the "if" directive. Configuration like location / { set $true 1; if ($true) { proxy_pass http://backend; } if ($true) { # nothing } } resulted in segmentation fault due to NULL pointer dereference as the upstream configuration wasn't initialized in an implicit location created by the last if(), but the r->content_handler was set due to first if(). Instead of committing a suicide by dereferencing a NULL pointer, return 500 (Internal Server Error) in such cases, i.e. if uscf is NULL. Better fix would be to avoid such cases by fixing the "if" directive handling, but it's out of scope of this patch. Prodded by Piotr Sikora.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 13 Dec 2012 16:05:59 +0000
parents 79c8e87b1fcb
children e2794322ec76
comparison
equal deleted inserted replaced
4963:9f4cdc7a8578 4964:2464ccebdb52
634 return; 634 return;
635 } 635 }
636 636
637 found: 637 found:
638 638
639 if (uscf == NULL) {
640 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
641 "no upstream configuration");
642 ngx_http_upstream_finalize_request(r, u,
643 NGX_HTTP_INTERNAL_SERVER_ERROR);
644 return;
645 }
646
639 if (uscf->peer.init(r, uscf) != NGX_OK) { 647 if (uscf->peer.init(r, uscf) != NGX_OK) {
640 ngx_http_upstream_finalize_request(r, u, 648 ngx_http_upstream_finalize_request(r, u,
641 NGX_HTTP_INTERNAL_SERVER_ERROR); 649 NGX_HTTP_INTERNAL_SERVER_ERROR);
642 return; 650 return;
643 } 651 }