From 9dba5580e462df3d845c7a6d4217b2f080600a98 Mon Sep 17 00:00:00 2001 From: Aleksey Konovkin Date: Mon, 28 May 2018 22:55:20 +0300 Subject: [PATCH] possible SIGSEGV on reload --- src/ngx_dynamic_shm.c | 4 ++-- src/ngx_dynamic_upstream_lua_module.c | 9 +++++++-- src/ngx_dynamic_upstream_stream_lua_module.c | 10 +++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/ngx_dynamic_shm.c b/src/ngx_dynamic_shm.c index 45c8624..3abb6b4 100644 --- a/src/ngx_dynamic_shm.c +++ b/src/ngx_dynamic_shm.c @@ -90,7 +90,7 @@ ngx_shm_copy_pairs(ngx_slab_pool_t *shpool, ngx_pair_t *src, ngx_uint_t count) ngx_pair_t *pairs = NULL; ngx_uint_t i; if (count) { - pairs = ngx_slab_calloc(shpool, count * sizeof(ngx_pair_t)); + pairs = ngx_slab_calloc_locked(shpool, count * sizeof(ngx_pair_t)); if (pairs != NULL) { for (i = 0; i < count; ++i) { 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 { ngx_uint_t *codes = NULL; if (count) { - codes = ngx_slab_calloc(shpool, count * sizeof(ngx_uint_t)); + codes = ngx_slab_calloc_locked(shpool, count * sizeof(ngx_uint_t)); if (codes != NULL) { ngx_memcpy(codes, src, count * sizeof(ngx_uint_t)); } diff --git a/src/ngx_dynamic_upstream_lua_module.c b/src/ngx_dynamic_upstream_lua_module.c index 511df77..82941b3 100644 --- a/src/ngx_dynamic_upstream_lua_module.c +++ b/src/ngx_dynamic_upstream_lua_module.c @@ -200,8 +200,11 @@ ngx_http_init_shm_zone(ngx_shm_zone_t *shm_zone, void *data) return NGX_OK; } - ucscf->data = ngx_slab_calloc(ucscf->shpool, sizeof(ngx_http_upstream_check_opts_t)); + ngx_shmtx_lock(&ucscf->shpool->mutex); + + ucscf->data = ngx_slab_calloc_locked(ucscf->shpool, sizeof(ngx_http_upstream_check_opts_t)); if (ucscf->data == NULL) { + ngx_shmtx_unlock(&ucscf->shpool->mutex); return NGX_ERROR; } @@ -233,6 +236,8 @@ ngx_http_init_shm_zone(ngx_shm_zone_t *shm_zone, void *data) rc = rc && (ucscf->data->request_headers || NULL == ucscf->conf->request_headers); rc = rc && (ucscf->data->response_codes || NULL == ucscf->conf->response_codes); + ngx_shmtx_unlock(&ucscf->shpool->mutex); + if (!rc) { return NGX_ERROR; } @@ -473,7 +478,7 @@ ngx_http_dynamic_upstream_lua_check_response_codes(ngx_conf_t *cf, ngx_command_t if (ucscf == NULL) { return NGX_CONF_ERROR; } - + value = cf->args->elts; ucscf->conf->response_codes_count = cf->args->nelts - 1; diff --git a/src/ngx_dynamic_upstream_stream_lua_module.c b/src/ngx_dynamic_upstream_stream_lua_module.c index 21da845..3916106 100644 --- a/src/ngx_dynamic_upstream_stream_lua_module.c +++ b/src/ngx_dynamic_upstream_stream_lua_module.c @@ -173,7 +173,7 @@ ngx_stream_dynamic_upstream_write_filter(ngx_stream_session_t *s, ngx_chain_t *i } if (uscf->srv_conf == NULL) { - goto skip; + goto skip; } 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) return NGX_OK; } - ucscf->data = ngx_slab_calloc(ucscf->shpool, sizeof(ngx_stream_upstream_check_opts_t)); + ngx_shmtx_lock(&ucscf->shpool->mutex); + + ucscf->data = ngx_slab_calloc_locked(ucscf->shpool, sizeof(ngx_stream_upstream_check_opts_t)); if (ucscf->data == NULL) { + ngx_shmtx_unlock(&ucscf->shpool->mutex); return NGX_ERROR; } @@ -316,11 +319,12 @@ ngx_stream_init_shm_zone(ngx_shm_zone_t *shm_zone, void *data) ucscf->data->request_body = ngx_shm_copy_string(ucscf->shpool, ucscf->conf->request_body); ucscf->data->response_body = ngx_shm_copy_string(ucscf->shpool, ucscf->conf->response_body); - rc = rc && (ucscf->data->upstream.data || NULL == ucscf->conf->upstream.data); rc = rc && (ucscf->data->request_body.data || NULL == ucscf->conf->request_body.data); rc = rc && (ucscf->data->response_body.data || NULL == ucscf->conf->response_body.data); + ngx_shmtx_unlock(&ucscf->shpool->mutex); + if (!rc) { return NGX_ERROR; }