changeset 5436:6aa75f4982ce

Gunzip: proper error handling on gunzipping an empty response. With previous code, an empty (malformed) response resulted in a request finalized without sending anything to a client.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 31 Oct 2013 04:16:20 +0400
parents 2bb2571d6e34
children dea321e5c021
files src/http/modules/ngx_http_gunzip_filter_module.c
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/http/modules/ngx_http_gunzip_filter_module.c
+++ b/src/http/modules/ngx_http_gunzip_filter_module.c
@@ -500,9 +500,13 @@ ngx_http_gunzip_filter_inflate(ngx_http_
         return NGX_OK;
     }
 
-    if (rc == Z_STREAM_END && ctx->flush == Z_FINISH
-        && ctx->zstream.avail_in == 0)
-    {
+    if (ctx->flush == Z_FINISH && ctx->zstream.avail_in == 0) {
+
+        if (rc != Z_STREAM_END) {
+            ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+                          "inflate() returned %d on response end", rc);
+            return NGX_ERROR;
+        }
 
         if (ngx_http_gunzip_filter_inflate_end(r, ctx) != NGX_OK) {
             return NGX_ERROR;