aboutsummaryrefslogtreecommitdiff
path: root/src/http/ngx_http_upstream_round_robin.c
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2011-08-18 17:04:52 +0000
committerMaxim Dounin <mdounin@mdounin.ru>2011-08-18 17:04:52 +0000
commitb7fcb430c156952fce4cb43a0a3cd81c2a5c939e (patch)
tree179d7f1be1edd2f49388c2086623bbfa2b76f8fd /src/http/ngx_http_upstream_round_robin.c
parent624fbe94a23e183dc356f9c3e696a816cb67acc2 (diff)
downloadnginx-b7fcb430c156952fce4cb43a0a3cd81c2a5c939e.tar.gz
nginx-b7fcb430c156952fce4cb43a0a3cd81c2a5c939e.zip
Upstream: properly allocate memory for tried flags.
Previous allocation only took into account number of non-backup servers, and this caused memory corruption with many backup servers. See report here: http://mailman.nginx.org/pipermail/nginx/2011-May/026531.html
Diffstat (limited to 'src/http/ngx_http_upstream_round_robin.c')
-rw-r--r--src/http/ngx_http_upstream_round_robin.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/http/ngx_http_upstream_round_robin.c b/src/http/ngx_http_upstream_round_robin.c
index c15790aa0..bb9a704b8 100644
--- a/src/http/ngx_http_upstream_round_robin.c
+++ b/src/http/ngx_http_upstream_round_robin.c
@@ -228,13 +228,18 @@ ngx_http_upstream_init_round_robin_peer(ngx_http_request_t *r,
rrp->peers = us->peer.data;
rrp->current = 0;
- if (rrp->peers->number <= 8 * sizeof(uintptr_t)) {
+ n = rrp->peers->number;
+
+ if (rrp->peers->next && rrp->peers->next->number > n) {
+ n = rrp->peers->next->number;
+ }
+
+ if (n <= 8 * sizeof(uintptr_t)) {
rrp->tried = &rrp->data;
rrp->data = 0;
} else {
- n = (rrp->peers->number + (8 * sizeof(uintptr_t) - 1))
- / (8 * sizeof(uintptr_t));
+ n = (n + (8 * sizeof(uintptr_t) - 1)) / (8 * sizeof(uintptr_t));
rrp->tried = ngx_pcalloc(r->pool, n * sizeof(uintptr_t));
if (rrp->tried == NULL) {