summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Kandaurov <pluknet@nginx.com>2017-03-28 14:21:38 +0300
committerSergey Kandaurov <pluknet@nginx.com>2017-03-28 14:21:38 +0300
commit9ad18e43ac2c9956399018cbb998337943988333 (patch)
tree5fa775ea2ea833bb65b18714d3eafd3539a784b5
parenteb017e75cf1b1d82179935b0e23d0c3451b33a87 (diff)
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.
-rw-r--r--src/http/modules/ngx_http_index_module.c6
-rw-r--r--src/http/modules/ngx_http_log_module.c5
-rw-r--r--src/http/ngx_http_core_module.c5
-rw-r--r--src/http/ngx_http_script.c6
-rw-r--r--src/stream/ngx_stream_log_module.c5
5 files changed, 24 insertions, 3 deletions
diff --git a/src/http/modules/ngx_http_index_module.c b/src/http/modules/ngx_http_index_module.c
index d3544db5b..c144b31c3 100644
--- a/src/http/modules/ngx_http_index_module.c
+++ b/src/http/modules/ngx_http_index_module.c
@@ -217,13 +217,13 @@ ngx_http_index_handler(ngx_http_request_t *r)
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 --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c
index 330dc7ecf..917ed55f4 100644
--- a/src/http/modules/ngx_http_log_module.c
+++ b/src/http/modules/ngx_http_log_module.c
@@ -552,6 +552,11 @@ ngx_http_log_script_write(ngx_http_request_t *r, ngx_http_log_script_t *script,
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 --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index c3957ba38..292671d13 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -1314,6 +1314,11 @@ ngx_http_core_try_files_phase(ngx_http_request_t *r,
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 --git a/src/http/ngx_http_script.c b/src/http/ngx_http_script.c
index cc4d67943..96f3ec696 100644
--- a/src/http/ngx_http_script.c
+++ b/src/http/ngx_http_script.c
@@ -1513,6 +1513,12 @@ ngx_http_script_file_code(ngx_http_script_engine_t *e)
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 --git a/src/stream/ngx_stream_log_module.c b/src/stream/ngx_stream_log_module.c
index 6b293403f..466bdda51 100644
--- a/src/stream/ngx_stream_log_module.c
+++ b/src/stream/ngx_stream_log_module.c
@@ -443,6 +443,11 @@ ngx_stream_log_script_write(ngx_stream_session_t *s,
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 */