From eb128df04574f1c0b9249445e40530df01d0a79d Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Thu, 21 Aug 2014 12:47:16 -0700 Subject: [PATCH] bugfix: added allocation failure check for ngx_array_init(). thanks Tatsuhiko Kubo for the patch in #414. --- 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 b9c9b022..ef0751fe 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 0fdc1358..ec7a893a 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