]> git.kaiwu.me - nginx.git/commitdiff
Postpone filter: prevented uninitialized r->out.
authorRoman Arutyunyan <arut@nginx.com>
Thu, 1 Mar 2018 15:38:39 +0000 (18:38 +0300)
committerRoman Arutyunyan <arut@nginx.com>
Thu, 1 Mar 2018 15:38:39 +0000 (18:38 +0300)
The r->out chain link could be left uninitialized in case of error.
A segfault could happen if the subrequest handler accessed it.
The issue was introduced in commit 20f139e9ffa8.

src/http/ngx_http_postpone_filter_module.c

index ded70b31b2ea8b494754ab33011cccc0de59421a..599d263e518f1770d8fc8a0d0e6197b25867d884 100644 (file)
@@ -191,11 +191,6 @@ ngx_http_postpone_filter_in_memory(ngx_http_request_t *r, ngx_chain_t *in)
                    "http postpone filter in memory");
 
     if (r->out == NULL) {
-        r->out = ngx_alloc_chain_link(r->pool);
-        if (r->out == NULL) {
-            return NGX_ERROR;
-        }
-
         clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
 
         if (r->headers_out.content_length_n != -1) {
@@ -218,6 +213,11 @@ ngx_http_postpone_filter_in_memory(ngx_http_request_t *r, ngx_chain_t *in)
 
         b->last_buf = 1;
 
+        r->out = ngx_alloc_chain_link(r->pool);
+        if (r->out == NULL) {
+            return NGX_ERROR;
+        }
+
         r->out->buf = b;
         r->out->next = NULL;
     }