# HG changeset patch # User Sergey Kandaurov # Date 1490700098 -10800 # Node ID 3fb9b5eb75c085e4c4b74c2aa0983a62aed85d54 # Parent a8d7c91398315eabfb751f2b112e3230a8701b49 Fixed ngx_open_cached_file() error handling. If of.err is 0, it means that there was a memory allocation error and no further logging and/or processing is needed. The of.failed string can be only accessed if of.err is not 0. diff -r a8d7c9139831 -r 3fb9b5eb75c0 src/http/modules/ngx_http_index_module.c --- a/src/http/modules/ngx_http_index_module.c Tue Mar 28 11:28:51 2017 +0300 +++ b/src/http/modules/ngx_http_index_module.c Tue Mar 28 14:21:38 2017 +0300 @@ -217,13 +217,13 @@ if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) != NGX_OK) { - ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, of.err, - "%s \"%s\" failed", of.failed, path.data); - if (of.err == 0) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, of.err, + "%s \"%s\" failed", of.failed, path.data); + #if (NGX_HAVE_OPENAT) if (of.err == NGX_EMLINK || of.err == NGX_ELOOP) diff -r a8d7c9139831 -r 3fb9b5eb75c0 src/http/modules/ngx_http_log_module.c --- a/src/http/modules/ngx_http_log_module.c Tue Mar 28 11:28:51 2017 +0300 +++ b/src/http/modules/ngx_http_log_module.c Tue Mar 28 14:21:38 2017 +0300 @@ -552,6 +552,11 @@ if (ngx_open_cached_file(llcf->open_file_cache, &log, &of, r->pool) != NGX_OK) { + if (of.err == 0) { + /* simulate successful logging */ + return len; + } + ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, "%s \"%s\" failed", of.failed, log.data); /* simulate successful logging */ diff -r a8d7c9139831 -r 3fb9b5eb75c0 src/http/ngx_http_core_module.c --- a/src/http/ngx_http_core_module.c Tue Mar 28 11:28:51 2017 +0300 +++ b/src/http/ngx_http_core_module.c Tue Mar 28 14:21:38 2017 +0300 @@ -1314,6 +1314,11 @@ if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) != NGX_OK) { + if (of.err == 0) { + ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); + return NGX_OK; + } + if (of.err != NGX_ENOENT && of.err != NGX_ENOTDIR && of.err != NGX_ENAMETOOLONG) diff -r a8d7c9139831 -r 3fb9b5eb75c0 src/http/ngx_http_script.c --- a/src/http/ngx_http_script.c Tue Mar 28 11:28:51 2017 +0300 +++ b/src/http/ngx_http_script.c Tue Mar 28 14:21:38 2017 +0300 @@ -1513,6 +1513,12 @@ if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) != NGX_OK) { + if (of.err == 0) { + e->ip = ngx_http_script_exit; + e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; + return; + } + if (of.err != NGX_ENOENT && of.err != NGX_ENOTDIR && of.err != NGX_ENAMETOOLONG) diff -r a8d7c9139831 -r 3fb9b5eb75c0 src/stream/ngx_stream_log_module.c --- a/src/stream/ngx_stream_log_module.c Tue Mar 28 11:28:51 2017 +0300 +++ b/src/stream/ngx_stream_log_module.c Tue Mar 28 14:21:38 2017 +0300 @@ -443,6 +443,11 @@ s->connection->pool) != NGX_OK) { + if (of.err == 0) { + /* simulate successful logging */ + return len; + } + ngx_log_error(NGX_LOG_CRIT, s->connection->log, ngx_errno, "%s \"%s\" failed", of.failed, log.data); /* simulate successful logging */