comparison src/http/ngx_http_upstream_round_robin.c @ 4011:9d4cbb09ae8b

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
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 18 Aug 2011 17:04:52 +0000
parents 74a93d3fdd85
children 4fc91bae6f83
comparison
equal deleted inserted replaced
4010:74a93d3fdd85 4011:9d4cbb09ae8b
226 } 226 }
227 227
228 rrp->peers = us->peer.data; 228 rrp->peers = us->peer.data;
229 rrp->current = 0; 229 rrp->current = 0;
230 230
231 if (rrp->peers->number <= 8 * sizeof(uintptr_t)) { 231 n = rrp->peers->number;
232
233 if (rrp->peers->next && rrp->peers->next->number > n) {
234 n = rrp->peers->next->number;
235 }
236
237 if (n <= 8 * sizeof(uintptr_t)) {
232 rrp->tried = &rrp->data; 238 rrp->tried = &rrp->data;
233 rrp->data = 0; 239 rrp->data = 0;
234 240
235 } else { 241 } else {
236 n = (rrp->peers->number + (8 * sizeof(uintptr_t) - 1)) 242 n = (n + (8 * sizeof(uintptr_t) - 1)) / (8 * sizeof(uintptr_t));
237 / (8 * sizeof(uintptr_t));
238 243
239 rrp->tried = ngx_pcalloc(r->pool, n * sizeof(uintptr_t)); 244 rrp->tried = ngx_pcalloc(r->pool, n * sizeof(uintptr_t));
240 if (rrp->tried == NULL) { 245 if (rrp->tried == NULL) {
241 return NGX_ERROR; 246 return NGX_ERROR;
242 } 247 }