]> git.kaiwu.me - nginx.git/commitdiff
Fixed ngx_open_cached_file() error handling.
authorSergey Kandaurov <pluknet@nginx.com>
Tue, 28 Mar 2017 11:21:38 +0000 (14:21 +0300)
committerSergey Kandaurov <pluknet@nginx.com>
Tue, 28 Mar 2017 11:21:38 +0000 (14:21 +0300)
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.

src/http/modules/ngx_http_index_module.c
src/http/modules/ngx_http_log_module.c
src/http/ngx_http_core_module.c
src/http/ngx_http_script.c
src/stream/ngx_stream_log_module.c

index d3544db5bf5b32726a5e8343035222f9be73cd7f..c144b31c3a977955e99741f8cde5a0a1743332d4 100644 (file)
@@ -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)
index 330dc7ecf79c304c5ec6bdd910d5787227999f19..917ed55f40ff0b324bb133a01dd3a2e5ea5adcc8 100644 (file)
@@ -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 */
index c3957ba38764f5ca818683b0b16db26822ca73af..292671d130081cc2ee3ceb179b5ec5b448f73f34 100644 (file)
@@ -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)
index cc4d67943560f3a86132baac60cc867278ff756a..96f3ec696513de3131dd75d69d10b2f496327d4d 100644 (file)
@@ -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)
index 6b293403f9311cca1464409dc38e7a8d74baee4a..466bdda514f83e7934eaaac56730c253d338dfa0 100644 (file)
@@ -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 */