[nginx] Slice filter: prevented slice redirection (ticket #1219).

Roman Arutyunyan arut at nginx.com
Mon Apr 3 10:44:55 UTC 2017


details:   http://hg.nginx.org/nginx/rev/3ff293cfdab8
branches:  
changeset: 6963:3ff293cfdab8
user:      Roman Arutyunyan <arut at nginx.com>
date:      Fri Mar 31 21:47:56 2017 +0300
description:
Slice filter: prevented slice redirection (ticket #1219).

When a slice subrequest was redirected to a new location, its context was lost.
After its completion, a new slice subrequest for the same slice was created.
This could lead to infinite loop.  Now the slice module makes sure each slice
subrequest starts output with the slice context available.

diffstat:

 src/http/modules/ngx_http_slice_filter_module.c |  12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diffs (43 lines):

diff -r a97ad1663ef4 -r 3ff293cfdab8 src/http/modules/ngx_http_slice_filter_module.c
--- a/src/http/modules/ngx_http_slice_filter_module.c	Tue Mar 28 14:03:57 2017 +0300
+++ b/src/http/modules/ngx_http_slice_filter_module.c	Fri Mar 31 21:47:56 2017 +0300
@@ -20,7 +20,8 @@ typedef struct {
     off_t                end;
     ngx_str_t            range;
     ngx_str_t            etag;
-    ngx_uint_t           last;  /* unsigned  last:1; */
+    unsigned             last:1;
+    unsigned             active:1;
     ngx_http_request_t  *sr;
 } ngx_http_slice_ctx_t;
 
@@ -170,6 +171,7 @@ ngx_http_slice_header_filter(ngx_http_re
     }
 
     ctx->start = end;
+    ctx->active = 1;
 
     r->headers_out.status = NGX_HTTP_OK;
     r->headers_out.status_line.len = 0;
@@ -238,6 +240,12 @@ ngx_http_slice_body_filter(ngx_http_requ
         return rc;
     }
 
+    if (!ctx->active) {
+        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+                      "missing slice response");
+        return NGX_ERROR;
+    }
+
     if (ctx->start >= ctx->end) {
         ngx_http_set_ctx(r, NULL, ngx_http_slice_filter_module);
         ngx_http_send_special(r, NGX_HTTP_LAST);
@@ -263,6 +271,8 @@ ngx_http_slice_body_filter(ngx_http_requ
                                  ctx->start + (off_t) slcf->size - 1)
                      - ctx->range.data;
 
+    ctx->active = 0;
+
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                    "http slice subrequest: \"%V\"", &ctx->range);
 


More information about the nginx-devel mailing list