From dc9fbaed852c51be659f5d7d03a655583cf97686 Mon Sep 17 00:00:00 2001 From: Tatsuhiko Kubo Date: Thu, 21 Aug 2014 15:06:02 +0900 Subject: [PATCH] bugfix: added allocation failure check for ngx_array_init(). --- src/ngx_http_lua_directive.c | 7 ++++++- src/ngx_http_lua_initworkerby.c | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/ngx_http_lua_directive.c b/src/ngx_http_lua_directive.c index b9c9b02227..ef0751fe66 100644 --- a/src/ngx_http_lua_directive.c +++ b/src/ngx_http_lua_directive.c @@ -51,7 +51,12 @@ ngx_http_lua_shared_dict(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_ERROR; } - ngx_array_init(lmcf->shm_zones, cf->pool, 2, sizeof(ngx_shm_zone_t *)); + if (ngx_array_init(lmcf->shm_zones, cf->pool, 2, + sizeof(ngx_shm_zone_t *)) + != NGX_OK) + { + return NGX_CONF_ERROR; + } } value = cf->args->elts; diff --git a/src/ngx_http_lua_initworkerby.c b/src/ngx_http_lua_initworkerby.c index 0fdc1358d3..ec7a893a74 100644 --- a/src/ngx_http_lua_initworkerby.c +++ b/src/ngx_http_lua_initworkerby.c @@ -82,14 +82,22 @@ ngx_http_lua_init_worker(ngx_cycle_t *cycle) #endif - ngx_array_init(&fake_cycle->listening, cycle->pool, - cycle->listening.nelts || 1, - sizeof(ngx_listening_t)); + if (ngx_array_init(&fake_cycle->listening, cycle->pool, + cycle->listening.nelts || 1, + sizeof(ngx_listening_t)) + != NGX_OK) + { + goto failed; + } #if defined(nginx_version) && nginx_version >= 1003007 - ngx_array_init(&fake_cycle->paths, cycle->pool, cycle->paths.nelts || 1, - sizeof(ngx_path_t *)); + if (ngx_array_init(&fake_cycle->paths, cycle->pool, cycle->paths.nelts || 1, + sizeof(ngx_path_t *)) + != NGX_OK) + { + goto failed; + } #endif