Fix copy of multiple peers when using upstream zone directive
Johan Ekenlycka
johan.ekenlycka at tui.se
Tue Sep 18 11:40:11 UTC 2018
# HG changeset patch
# User Johan Ekenlycka <johan.ekenlycka at gmail.com>
# Date 1537270510 -7200
# Tue Sep 18 13:35:10 2018 +0200
# Node ID f6a4b9360aaa102749233e14d4b49120dae46d9b
# Parent 87d2ea860f380dc8418c97c0163412f53c2d008e
Fix copy of multiple peers when using upstream zone
Iteration of destination pointer and next pointer on peers was
not performed correctly, resulting in NULL peers when multiple
peers in upstream.
diff -r 87d2ea860f38 -r f6a4b9360aaa src/http/modules/ngx_http_upstream_zone_module.c
--- a/src/http/modules/ngx_http_upstream_zone_module.c Mon Sep 10 18:57:39 2018 +0300
+++ b/src/http/modules/ngx_http_upstream_zone_module.c Tue Sep 18 13:35:10 2018 +0200
@@ -187,8 +187,9 @@
ngx_http_upstream_zone_copy_peers(ngx_slab_pool_t *shpool,
ngx_http_upstream_srv_conf_t *uscf)
{
+ ngx_uint_t i;
ngx_str_t *name;
- ngx_http_upstream_rr_peer_t *peer, **peerp;
+ ngx_http_upstream_rr_peer_t *peer;
ngx_http_upstream_rr_peers_t *peers, *backup;
peers = ngx_slab_alloc(shpool, sizeof(ngx_http_upstream_rr_peers_t));
@@ -215,14 +216,17 @@
peers->shpool = shpool;
- for (peerp = &peers->peer; *peerp; peerp = &peer->next) {
+ for (i = 0; i < peers->number; i++) {
/* pool is unlocked */
- peer = ngx_http_upstream_zone_copy_peer(peers, *peerp);
+ peer = ngx_http_upstream_zone_copy_peer(peers, &peers->peer[i]);
if (peer == NULL) {
return NULL;
}
+ if (i > 0) {
+ peers->peer[i - 1].next = peer;
+ }
- *peerp = peer;
+ peers->peer[i] = *peer;
}
if (peers->next == NULL) {
@@ -240,14 +244,18 @@
backup->shpool = shpool;
- for (peerp = &backup->peer; *peerp; peerp = &peer->next) {
+
+ for (i = 0; i < backup->number; i++) {
/* pool is unlocked */
- peer = ngx_http_upstream_zone_copy_peer(backup, *peerp);
+ peer = ngx_http_upstream_zone_copy_peer(backup, &backup->peer[i]);
if (peer == NULL) {
return NULL;
}
+ if (i > 0) {
+ backup->peer[i - 1].next = peer;
+ }
- *peerp = peer;
+ backup->peer[i] = *peer;
}
peers->next = backup;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20180918/d05ce677/attachment.html>
More information about the nginx-devel
mailing list