Skip to content

Commit 9dba558

Browse files
committed
possible SIGSEGV on reload
1 parent 1ce0b66 commit 9dba558

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/ngx_dynamic_shm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ ngx_shm_copy_pairs(ngx_slab_pool_t *shpool, ngx_pair_t *src, ngx_uint_t count)
9090
ngx_pair_t *pairs = NULL;
9191
ngx_uint_t i;
9292
if (count) {
93-
pairs = ngx_slab_calloc(shpool, count * sizeof(ngx_pair_t));
93+
pairs = ngx_slab_calloc_locked(shpool, count * sizeof(ngx_pair_t));
9494
if (pairs != NULL) {
9595
for (i = 0; i < count; ++i) {
9696
pairs[i].name = ngx_shm_copy_string(shpool, src[i].name);
@@ -110,7 +110,7 @@ ngx_shm_copy_uint_vec(ngx_slab_pool_t *shpool, ngx_uint_t *src, ngx_uint_t count
110110
{
111111
ngx_uint_t *codes = NULL;
112112
if (count) {
113-
codes = ngx_slab_calloc(shpool, count * sizeof(ngx_uint_t));
113+
codes = ngx_slab_calloc_locked(shpool, count * sizeof(ngx_uint_t));
114114
if (codes != NULL) {
115115
ngx_memcpy(codes, src, count * sizeof(ngx_uint_t));
116116
}

src/ngx_dynamic_upstream_lua_module.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,11 @@ ngx_http_init_shm_zone(ngx_shm_zone_t *shm_zone, void *data)
200200
return NGX_OK;
201201
}
202202

203-
ucscf->data = ngx_slab_calloc(ucscf->shpool, sizeof(ngx_http_upstream_check_opts_t));
203+
ngx_shmtx_lock(&ucscf->shpool->mutex);
204+
205+
ucscf->data = ngx_slab_calloc_locked(ucscf->shpool, sizeof(ngx_http_upstream_check_opts_t));
204206
if (ucscf->data == NULL) {
207+
ngx_shmtx_unlock(&ucscf->shpool->mutex);
205208
return NGX_ERROR;
206209
}
207210

@@ -233,6 +236,8 @@ ngx_http_init_shm_zone(ngx_shm_zone_t *shm_zone, void *data)
233236
rc = rc && (ucscf->data->request_headers || NULL == ucscf->conf->request_headers);
234237
rc = rc && (ucscf->data->response_codes || NULL == ucscf->conf->response_codes);
235238

239+
ngx_shmtx_unlock(&ucscf->shpool->mutex);
240+
236241
if (!rc) {
237242
return NGX_ERROR;
238243
}
@@ -473,7 +478,7 @@ ngx_http_dynamic_upstream_lua_check_response_codes(ngx_conf_t *cf, ngx_command_t
473478
if (ucscf == NULL) {
474479
return NGX_CONF_ERROR;
475480
}
476-
481+
477482
value = cf->args->elts;
478483

479484
ucscf->conf->response_codes_count = cf->args->nelts - 1;

src/ngx_dynamic_upstream_stream_lua_module.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ ngx_stream_dynamic_upstream_write_filter(ngx_stream_session_t *s, ngx_chain_t *i
173173
}
174174

175175
if (uscf->srv_conf == NULL) {
176-
goto skip;
176+
goto skip;
177177
}
178178

179179
ucscf = ngx_stream_conf_upstream_srv_conf(uscf, ngx_stream_dynamic_upstream_lua_module);
@@ -303,8 +303,11 @@ ngx_stream_init_shm_zone(ngx_shm_zone_t *shm_zone, void *data)
303303
return NGX_OK;
304304
}
305305

306-
ucscf->data = ngx_slab_calloc(ucscf->shpool, sizeof(ngx_stream_upstream_check_opts_t));
306+
ngx_shmtx_lock(&ucscf->shpool->mutex);
307+
308+
ucscf->data = ngx_slab_calloc_locked(ucscf->shpool, sizeof(ngx_stream_upstream_check_opts_t));
307309
if (ucscf->data == NULL) {
310+
ngx_shmtx_unlock(&ucscf->shpool->mutex);
308311
return NGX_ERROR;
309312
}
310313

@@ -316,11 +319,12 @@ ngx_stream_init_shm_zone(ngx_shm_zone_t *shm_zone, void *data)
316319
ucscf->data->request_body = ngx_shm_copy_string(ucscf->shpool, ucscf->conf->request_body);
317320
ucscf->data->response_body = ngx_shm_copy_string(ucscf->shpool, ucscf->conf->response_body);
318321

319-
320322
rc = rc && (ucscf->data->upstream.data || NULL == ucscf->conf->upstream.data);
321323
rc = rc && (ucscf->data->request_body.data || NULL == ucscf->conf->request_body.data);
322324
rc = rc && (ucscf->data->response_body.data || NULL == ucscf->conf->response_body.data);
323325

326+
ngx_shmtx_unlock(&ucscf->shpool->mutex);
327+
324328
if (!rc) {
325329
return NGX_ERROR;
326330
}

0 commit comments

Comments
 (0)