Skip to content

Commit

Permalink
fix critical memory error and support for the same peer multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
splitice committed Oct 30, 2024
1 parent 5c291ee commit e772b3c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/ngx_http_upstream_jdomain_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ ngx_http_upstream_init_jdomain(ngx_conf_t *cf, ngx_http_upstream_srv_conf_t *us)
ngx_http_upstream_rr_peer_t *peer;
ngx_http_upstream_rr_peer_t **peerp;
ngx_http_upstream_rr_peers_t *peers;
ngx_uint_t i;
ngx_uint_t j;
ngx_uint_t i, k;
ngx_int_t j;

ngx_log_debug0(NGX_LOG_DEBUG_HTTP, cf->log, 0, "ngx_http_upstream_jdomain_module: init jdomain");

Expand All @@ -161,10 +161,27 @@ ngx_http_upstream_init_jdomain(ngx_conf_t *cf, ngx_http_upstream_srv_conf_t *us)
peerp = instance[i].state.data.peerps->elts;
j = 0;

/* Find the starting position for our peerps */
for (k = 0; k < i; k++) {
if (instance[i].state.data.server->name.len == instance[k].state.data.server->name.len &&
ngx_strncmp(instance[i].state.data.server->name.data, instance[k].state.data.server->name.data, peer->server.len) == 0) {
j -= instance[k].conf.max_ips;
}
}

for (peer = peers->peer; peer; peer = peer->next) {
if (instance[i].state.data.server->name.len == peer->server.len &&
ngx_strncmp(instance[i].state.data.server->name.data, peer->server.data, peer->server.len) == 0) {
if (j < 0) {
j++;
continue;
}

peerp[j++] = peer;

if (j == instance[i].conf.max_ips) {
break;
}
}
}

Expand Down

0 comments on commit e772b3c

Please sign in to comment.