src/http/ngx_http_header_filter_module.c:430: error: Buffer Overrun L3
  Offset added: 9 Size: [0, +oo].

src/http/ngx_http_header_filter_module.c:348:9: <Length trace>
346.         }
347. 
348.         len += sizeof("Location: https://") - 1
             ^
349.                + host.len
350.                + r->headers_out.location->value.len + 2;

src/http/ngx_http_header_filter_module.c:348:9: Assignment
346.         }
347. 
348.         len += sizeof("Location: https://") - 1
             ^
349.                + host.len
350.                + r->headers_out.location->value.len + 2;

src/http/ngx_http_header_filter_module.c:377:9: Assignment
375. 
376.     if (r->keepalive) {
377.         len += sizeof("Connection: keep-alive" CRLF) - 1;
             ^
378. 
379.         /*

src/http/ngx_http_header_filter_module.c:424:9: Call
422.     }
423. 
424.     b = ngx_create_temp_buf(r->pool, len);
             ^
425.     if (b == NULL) {
426.         return NGX_ERROR;

src/core/ngx_buf.c:11:1: Parameter `size`
   9. 
  10. 
  11. ngx_buf_t *
      ^
  12. ngx_create_temp_buf(ngx_pool_t *pool, size_t size)
  13. {

src/core/ngx_buf.c:21:16: Call
  19.     }
  20. 
  21.     b->start = ngx_palloc(pool, size);
                     ^
  22.     if (b->start == NULL) {
  23.         return NULL;

src/core/ngx_palloc.c:125:13: Assignment
    123. 
    124.         do {
    125.             m = ngx_align_ptr(p->d.last, NGX_ALIGNMENT);
                     ^
    126. 
    127.             if ((size_t) (p->d.end - m) >= size) {

src/core/ngx_palloc.c:130:17: Assignment
    128.                 p->d.last = m + size;
    129. 
    130.                 return m;
                         ^
    131.             }
    132. 

src/core/ngx_buf.c:21:5: Assignment
  19.     }
  20. 
  21.     b->start = ngx_palloc(pool, size);
          ^
  22.     if (b->start == NULL) {
  23.         return NULL;

src/core/ngx_buf.c:38:5: Assignment
  36. 
  37.     b->pos = b->start;
  38.     b->last = b->start;
          ^
  39.     b->end = b->last + size;
  40.     b->temporary = 1;

src/http/ngx_http_header_filter_module.c:430:15: Array access: Offset added: 9 Size: [0, +oo]
428. 
429.     /* "HTTP/1.x " */
430.     b->last = ngx_cpymem(b->last, "HTTP/1.1 ", sizeof("HTTP/1.x ") - 1);
                   ^
431. 
432.     /* status line */

static ngx_int_t
ngx_http_header_filter(ngx_http_request_t *r)
{
    u_char                    *p;
    size_t                     len;
    ngx_str_t                  host, *status_line;
    ngx_buf_t                 *b;
    ngx_uint_t                 status, i, port;
    ngx_chain_t                out;
    ngx_list_part_t           *part;
    ngx_table_elt_t           *header;
    ngx_http_core_loc_conf_t  *clcf;
    ngx_http_core_srv_conf_t  *cscf;
    struct sockaddr_in        *sin;
#if (NGX_HAVE_INET6)
    struct sockaddr_in6       *sin6;
#endif
    u_char                     addr[NGX_SOCKADDR_STRLEN];
    r->header_sent = 1;
    if (r != r->main) {
        return NGX_OK;
    }
    if (r->http_version < NGX_HTTP_VERSION_10) {
        return NGX_OK;
    }
    if (r->method == NGX_HTTP_HEAD) {
        r->header_only = 1;
    }
    if (r->headers_out.last_modified_time != -1) {
        if (r->headers_out.status != NGX_HTTP_OK
            && r->headers_out.status != NGX_HTTP_PARTIAL_CONTENT
            && r->headers_out.status != NGX_HTTP_NOT_MODIFIED)
        {
            r->headers_out.last_modified_time = -1;
            r->headers_out.last_modified = NULL;
        }
    }
    len = sizeof("HTTP/1.x ") - 1 + sizeof(CRLF) - 1
          + sizeof(CRLF) - 1;
    if (r->headers_out.status_line.len) {
        len += r->headers_out.status_line.len;
        status_line = &r->headers_out.status_line;
#if (NGX_SUPPRESS_WARN)
        status = 0;
#endif
    } else {
        status = r->headers_out.status;
        if (status >= NGX_HTTP_OK
            && status < NGX_HTTP_LAST_LEVEL_200)
        {
            if (status == NGX_HTTP_NO_CONTENT) {
                r->header_only = 1;
                r->headers_out.content_type.len = 0;
                r->headers_out.content_type.data = NULL;
                r->headers_out.last_modified_time = -1;
                r->headers_out.last_modified = NULL;
                r->headers_out.content_length = NULL;
                r->headers_out.content_length_n = -1;
            }
            status -= NGX_HTTP_OK;
            status_line = &ngx_http_status_lines[status];
            len += ngx_http_status_lines[status].len;
        } else if (status >= NGX_HTTP_MOVED_PERMANENTLY
                   && status < NGX_HTTP_LAST_LEVEL_300)
        {
            if (status == NGX_HTTP_NOT_MODIFIED) {
                r->header_only = 1;
            }
            status = status - NGX_HTTP_MOVED_PERMANENTLY + NGX_HTTP_LEVEL_200;
            status_line = &ngx_http_status_lines[status];
            len += ngx_http_status_lines[status].len;
        } else if (status >= NGX_HTTP_BAD_REQUEST
                   && status < NGX_HTTP_LAST_LEVEL_400)
        {
            status = status - NGX_HTTP_BAD_REQUEST
                            + NGX_HTTP_LEVEL_200
                            + NGX_HTTP_LEVEL_300;
            status_line = &ngx_http_status_lines[status];
            len += ngx_http_status_lines[status].len;
        } else if (status >= NGX_HTTP_INTERNAL_SERVER_ERROR
                   && status < NGX_HTTP_LAST_LEVEL_500)
        {
            status = status - NGX_HTTP_INTERNAL_SERVER_ERROR
                            + NGX_HTTP_LEVEL_200
                            + NGX_HTTP_LEVEL_300
                            + NGX_HTTP_LEVEL_400;
            status_line = &ngx_http_status_lines[status];
            len += ngx_http_status_lines[status].len;
        } else {
            len += NGX_INT_T_LEN;
            status_line = NULL;
        }
    }
    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
    if (r->headers_out.server == NULL) {
        len += clcf->server_tokens ? sizeof(ngx_http_server_full_string) - 1:
                                     sizeof(ngx_http_server_string) - 1;
    }
    if (r->headers_out.date == NULL) {
        len += sizeof("Date: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1;
    }
    if (r->headers_out.content_type.len) {
        len += sizeof("Content-Type: ") - 1
               + r->headers_out.content_type.len + 2;
        if (r->headers_out.content_type_len == r->headers_out.content_type.len
            && r->headers_out.charset.len)
        {
            len += sizeof("; charset=") - 1 + r->headers_out.charset.len;
        }
    }
    if (r->headers_out.content_length == NULL
        && r->headers_out.content_length_n >= 0)
    {
        len += sizeof("Content-Length: ") - 1 + NGX_OFF_T_LEN + 2;
    }
    if (r->headers_out.last_modified == NULL
        && r->headers_out.last_modified_time != -1)
    {
        len += sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1;
    }
    if (r->headers_out.location
        && r->headers_out.location->value.len
        && r->headers_out.location->value.data[0] == '/')
    {
        r->headers_out.location->hash = 0;
        if (clcf->server_name_in_redirect) {
            cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
            host = cscf->server_name;
        } else if (r->headers_in.server.len) {
            host = r->headers_in.server;
        } else {
            host.len = NGX_SOCKADDR_STRLEN;
            host.data = addr;
            if (ngx_http_server_addr(r, &host) != NGX_OK) {
                return NGX_ERROR;
            }
        }
        switch (r->connection->local_sockaddr->sa_family) {
#if (NGX_HAVE_INET6)
        case AF_INET6:
            sin6 = (struct sockaddr_in6 *) r->connection->local_sockaddr;
            port = ntohs(sin6->sin6_port);
            break;
#endif
        default:
            sin = (struct sockaddr_in *) r->connection->local_sockaddr;
            port = ntohs(sin->sin_port);
            break;
        }
        len += sizeof("Location: https://") - 1
               + host.len
               + r->headers_out.location->value.len + 2;
        if (clcf->port_in_redirect) {
#if (NGX_HTTP_SSL)
            if (r->connection->ssl)
                port = (port == 443) ? 0 : port;
            else
#endif
                port = (port == 80) ? 0 : port;
        }
        if (port) {
            len += sizeof(":65535") - 1;
        }
    } else {
        host.len = 0;
        host.data = NULL;
        port = 0;
    }
    if (r->chunked) {
        len += sizeof("Transfer-Encoding: chunked" CRLF) - 1;
    }
    if (r->keepalive) {
        len += sizeof("Connection: keep-alive" CRLF) - 1;
        if (clcf->keepalive_header) {
            len += sizeof("Keep-Alive: timeout=") - 1 + NGX_TIME_T_LEN + 2;
        }
    } else {
        len += sizeof("Connection: closed" CRLF) - 1;
    }
#if (NGX_HTTP_GZIP)
    if (r->gzip && clcf->gzip_vary) {
        len += sizeof("Vary: Accept-Encoding" CRLF) - 1;
    }
#endif
    part = &r->headers_out.headers.part;
    header = part->elts;
    for (i = 0;  ; i++) {
        if (i >= part->nelts) {
            if (part->next == NULL) {
                break;
            }
            part = part->next;
            header = part->elts;
            i = 0;
        }
        if (header[i].hash == 0) {
            continue;
        }
        len += header[i].key.len + sizeof(": ") - 1 + header[i].value.len
               + sizeof(CRLF) - 1;
    }
    b = ngx_create_temp_buf(r->pool, len);
    if (b == NULL) {
        return NGX_ERROR;
    }
    b->last = ngx_cpymem(b->last, "HTTP/1.1 ", sizeof("HTTP/1.x ") - 1);
    if (status_line) {
        b->last = ngx_copy(b->last, status_line->data, status_line->len);
    } else {
        b->last = ngx_sprintf(b->last, "%ui", status);
    }
    *b->last++ = CR; *b->last++ = LF;
    if (r->headers_out.server == NULL) {
        if (clcf->server_tokens) {
            p = (u_char *) ngx_http_server_full_string;
            len = sizeof(ngx_http_server_full_string) - 1;
        } else {
            p = (u_char *) ngx_http_server_string;
            len = sizeof(ngx_http_server_string) - 1;
        }
        b->last = ngx_cpymem(b->last, p, len);
    }
    if (r->headers_out.date == NULL) {
        b->last = ngx_cpymem(b->last, "Date: ", sizeof("Date: ") - 1);
        b->last = ngx_cpymem(b->last, ngx_cached_http_time.data,
                             ngx_cached_http_time.len);
        *b->last++ = CR; *b->last++ = LF;
    }
    if (r->headers_out.content_type.len) {
        b->last = ngx_cpymem(b->last, "Content-Type: ",
                             sizeof("Content-Type: ") - 1);
        p = b->last;
        b->last = ngx_copy(b->last, r->headers_out.content_type.data,
                           r->headers_out.content_type.len);
        if (r->headers_out.content_type_len == r->headers_out.content_type.len
            && r->headers_out.charset.len)
        {
            b->last = ngx_cpymem(b->last, "; charset=",
                                 sizeof("; charset=") - 1);
            b->last = ngx_copy(b->last, r->headers_out.charset.data,
                               r->headers_out.charset.len);
            r->headers_out.content_type.len = b->last - p;
            r->headers_out.content_type.data = p;
        }
        *b->last++ = CR; *b->last++ = LF;
    }
    if (r->headers_out.content_length == NULL
        && r->headers_out.content_length_n >= 0)
    {
        b->last = ngx_sprintf(b->last, "Content-Length: %O" CRLF,
                              r->headers_out.content_length_n);
    }
    if (r->headers_out.last_modified == NULL
        && r->headers_out.last_modified_time != -1)
    {
        b->last = ngx_cpymem(b->last, "Last-Modified: ",
                             sizeof("Last-Modified: ") - 1);
        b->last = ngx_http_time(b->last, r->headers_out.last_modified_time);
        *b->last++ = CR; *b->last++ = LF;
    }
    if (host.data) {
        p = b->last + sizeof("Location: ") - 1;
        b->last = ngx_cpymem(b->last, "Location: http",
                             sizeof("Location: http") - 1);
#if (NGX_HTTP_SSL)
        if (r->connection->ssl) {
            *b->last++ ='s';
        }
#endif
        *b->last++ = ':'; *b->last++ = '/'; *b->last++ = '/';
        b->last = ngx_copy(b->last, host.data, host.len);
        if (port) {
            b->last = ngx_sprintf(b->last, ":%ui", port);
        }
        b->last = ngx_copy(b->last, r->headers_out.location->value.data,
                           r->headers_out.location->value.len);
        r->headers_out.location->value.len = b->last - p;
        r->headers_out.location->value.data = p;
        r->headers_out.location->key.len = sizeof("Location: ") - 1;
        r->headers_out.location->key.data = (u_char *) "Location: ";
        *b->last++ = CR; *b->last++ = LF;
    }
    if (r->chunked) {
        b->last = ngx_cpymem(b->last, "Transfer-Encoding: chunked" CRLF,
                             sizeof("Transfer-Encoding: chunked" CRLF) - 1);
    }
    if (r->keepalive) {
        b->last = ngx_cpymem(b->last, "Connection: keep-alive" CRLF,
                             sizeof("Connection: keep-alive" CRLF) - 1);
        if (clcf->keepalive_header) {
            b->last = ngx_sprintf(b->last, "Keep-Alive: timeout=%T" CRLF,
                                  clcf->keepalive_header);
        }
    } else {
        b->last = ngx_cpymem(b->last, "Connection: close" CRLF,
                             sizeof("Connection: close" CRLF) - 1);
    }
#if (NGX_HTTP_GZIP)
    if (r->gzip && clcf->gzip_vary) {
        b->last = ngx_cpymem(b->last, "Vary: Accept-Encoding" CRLF,
                             sizeof("Vary: Accept-Encoding" CRLF) - 1);
    }
#endif
    part = &r->headers_out.headers.part;
    header = part->elts;
    for (i = 0;  ; i++) {
        if (i >= part->nelts) {
            if (part->next == NULL) {
                break;
            }
            part = part->next;
            header = part->elts;
            i = 0;
        }
        if (header[i].hash == 0) {
            continue;
        }
        b->last = ngx_copy(b->last, header[i].key.data, header[i].key.len);
        *b->last++ = ':'; *b->last++ = ' ';
        b->last = ngx_copy(b->last, header[i].value.data, header[i].value.len);
        *b->last++ = CR; *b->last++ = LF;
    }
    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                   "%*s", (size_t) (b->last - b->pos), b->pos);
    *b->last++ = CR; *b->last++ = LF;
    r->header_size = b->last - b->pos;
    if (r->header_only) {
        b->last_buf = 1;
    }
    out.buf = b;
    out.next = NULL;
    return ngx_http_write_filter(r, &out);
}
['static ngx_int_t\nngx_http_header_filter(ngx_http_request_t *r)\n{\n    u_char                    *p;\n    size_t                     len;\n    ngx_str_t                  host, *status_line;\n    ngx_buf_t                 *b;\n    ngx_uint_t                 status, i, port;\n    ngx_chain_t                out;\n    ngx_list_part_t           *part;\n    ngx_table_elt_t           *header;\n    ngx_http_core_loc_conf_t  *clcf;\n    ngx_http_core_srv_conf_t  *cscf;\n    struct sockaddr_in        *sin;\n#if (NGX_HAVE_INET6)\n    struct sockaddr_in6       *sin6;\n#endif\n    u_char                     addr[NGX_SOCKADDR_STRLEN];\n    r->header_sent = 1;\n    if (r != r->main) {\n        return NGX_OK;\n    }\n    if (r->http_version < NGX_HTTP_VERSION_10) {\n        return NGX_OK;\n    }\n    if (r->method == NGX_HTTP_HEAD) {\n        r->header_only = 1;\n    }\n    if (r->headers_out.last_modified_time != -1) {\n        if (r->headers_out.status != NGX_HTTP_OK\n            && r->headers_out.status != NGX_HTTP_PARTIAL_CONTENT\n            && r->headers_out.status != NGX_HTTP_NOT_MODIFIED)\n        {\n            r->headers_out.last_modified_time = -1;\n            r->headers_out.last_modified = NULL;\n        }\n    }\n    len = sizeof("HTTP/1.x ") - 1 + sizeof(CRLF) - 1\n          + sizeof(CRLF) - 1;\n    if (r->headers_out.status_line.len) {\n        len += r->headers_out.status_line.len;\n        status_line = &r->headers_out.status_line;\n#if (NGX_SUPPRESS_WARN)\n        status = 0;\n#endif\n    } else {\n        status = r->headers_out.status;\n        if (status >= NGX_HTTP_OK\n            && status < NGX_HTTP_LAST_LEVEL_200)\n        {\n            if (status == NGX_HTTP_NO_CONTENT) {\n                r->header_only = 1;\n                r->headers_out.content_type.len = 0;\n                r->headers_out.content_type.data = NULL;\n                r->headers_out.last_modified_time = -1;\n                r->headers_out.last_modified = NULL;\n                r->headers_out.content_length = NULL;\n                r->headers_out.content_length_n = -1;\n            }\n            status -= NGX_HTTP_OK;\n            status_line = &ngx_http_status_lines[status];\n            len += ngx_http_status_lines[status].len;\n        } else if (status >= NGX_HTTP_MOVED_PERMANENTLY\n                   && status < NGX_HTTP_LAST_LEVEL_300)\n        {\n            if (status == NGX_HTTP_NOT_MODIFIED) {\n                r->header_only = 1;\n            }\n            status = status - NGX_HTTP_MOVED_PERMANENTLY + NGX_HTTP_LEVEL_200;\n            status_line = &ngx_http_status_lines[status];\n            len += ngx_http_status_lines[status].len;\n        } else if (status >= NGX_HTTP_BAD_REQUEST\n                   && status < NGX_HTTP_LAST_LEVEL_400)\n        {\n            status = status - NGX_HTTP_BAD_REQUEST\n                            + NGX_HTTP_LEVEL_200\n                            + NGX_HTTP_LEVEL_300;\n            status_line = &ngx_http_status_lines[status];\n            len += ngx_http_status_lines[status].len;\n        } else if (status >= NGX_HTTP_INTERNAL_SERVER_ERROR\n                   && status < NGX_HTTP_LAST_LEVEL_500)\n        {\n            status = status - NGX_HTTP_INTERNAL_SERVER_ERROR\n                            + NGX_HTTP_LEVEL_200\n                            + NGX_HTTP_LEVEL_300\n                            + NGX_HTTP_LEVEL_400;\n            status_line = &ngx_http_status_lines[status];\n            len += ngx_http_status_lines[status].len;\n        } else {\n            len += NGX_INT_T_LEN;\n            status_line = NULL;\n        }\n    }\n    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n    if (r->headers_out.server == NULL) {\n        len += clcf->server_tokens ? sizeof(ngx_http_server_full_string) - 1:\n                                     sizeof(ngx_http_server_string) - 1;\n    }\n    if (r->headers_out.date == NULL) {\n        len += sizeof("Date: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1;\n    }\n    if (r->headers_out.content_type.len) {\n        len += sizeof("Content-Type: ") - 1\n               + r->headers_out.content_type.len + 2;\n        if (r->headers_out.content_type_len == r->headers_out.content_type.len\n            && r->headers_out.charset.len)\n        {\n            len += sizeof("; charset=") - 1 + r->headers_out.charset.len;\n        }\n    }\n    if (r->headers_out.content_length == NULL\n        && r->headers_out.content_length_n >= 0)\n    {\n        len += sizeof("Content-Length: ") - 1 + NGX_OFF_T_LEN + 2;\n    }\n    if (r->headers_out.last_modified == NULL\n        && r->headers_out.last_modified_time != -1)\n    {\n        len += sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1;\n    }\n    if (r->headers_out.location\n        && r->headers_out.location->value.len\n        && r->headers_out.location->value.data[0] == \'/\')\n    {\n        r->headers_out.location->hash = 0;\n        if (clcf->server_name_in_redirect) {\n            cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);\n            host = cscf->server_name;\n        } else if (r->headers_in.server.len) {\n            host = r->headers_in.server;\n        } else {\n            host.len = NGX_SOCKADDR_STRLEN;\n            host.data = addr;\n            if (ngx_http_server_addr(r, &host) != NGX_OK) {\n                return NGX_ERROR;\n            }\n        }\n        switch (r->connection->local_sockaddr->sa_family) {\n#if (NGX_HAVE_INET6)\n        case AF_INET6:\n            sin6 = (struct sockaddr_in6 *) r->connection->local_sockaddr;\n            port = ntohs(sin6->sin6_port);\n            break;\n#endif\n        default:\n            sin = (struct sockaddr_in *) r->connection->local_sockaddr;\n            port = ntohs(sin->sin_port);\n            break;\n        }\n        len += sizeof("Location: https://") - 1\n               + host.len\n               + r->headers_out.location->value.len + 2;\n        if (clcf->port_in_redirect) {\n#if (NGX_HTTP_SSL)\n            if (r->connection->ssl)\n                port = (port == 443) ? 0 : port;\n            else\n#endif\n                port = (port == 80) ? 0 : port;\n        }\n        if (port) {\n            len += sizeof(":65535") - 1;\n        }\n    } else {\n        host.len = 0;\n        host.data = NULL;\n        port = 0;\n    }\n    if (r->chunked) {\n        len += sizeof("Transfer-Encoding: chunked" CRLF) - 1;\n    }\n    if (r->keepalive) {\n        len += sizeof("Connection: keep-alive" CRLF) - 1;\n        if (clcf->keepalive_header) {\n            len += sizeof("Keep-Alive: timeout=") - 1 + NGX_TIME_T_LEN + 2;\n        }\n    } else {\n        len += sizeof("Connection: closed" CRLF) - 1;\n    }\n#if (NGX_HTTP_GZIP)\n    if (r->gzip && clcf->gzip_vary) {\n        len += sizeof("Vary: Accept-Encoding" CRLF) - 1;\n    }\n#endif\n    part = &r->headers_out.headers.part;\n    header = part->elts;\n    for (i = 0;  ; i++) {\n        if (i >= part->nelts) {\n            if (part->next == NULL) {\n                break;\n            }\n            part = part->next;\n            header = part->elts;\n            i = 0;\n        }\n        if (header[i].hash == 0) {\n            continue;\n        }\n        len += header[i].key.len + sizeof(": ") - 1 + header[i].value.len\n               + sizeof(CRLF) - 1;\n    }\n    b = ngx_create_temp_buf(r->pool, len);\n    if (b == NULL) {\n        return NGX_ERROR;\n    }\n    b->last = ngx_cpymem(b->last, "HTTP/1.1 ", sizeof("HTTP/1.x ") - 1);\n    if (status_line) {\n        b->last = ngx_copy(b->last, status_line->data, status_line->len);\n    } else {\n        b->last = ngx_sprintf(b->last, "%ui", status);\n    }\n    *b->last++ = CR; *b->last++ = LF;\n    if (r->headers_out.server == NULL) {\n        if (clcf->server_tokens) {\n            p = (u_char *) ngx_http_server_full_string;\n            len = sizeof(ngx_http_server_full_string) - 1;\n        } else {\n            p = (u_char *) ngx_http_server_string;\n            len = sizeof(ngx_http_server_string) - 1;\n        }\n        b->last = ngx_cpymem(b->last, p, len);\n    }\n    if (r->headers_out.date == NULL) {\n        b->last = ngx_cpymem(b->last, "Date: ", sizeof("Date: ") - 1);\n        b->last = ngx_cpymem(b->last, ngx_cached_http_time.data,\n                             ngx_cached_http_time.len);\n        *b->last++ = CR; *b->last++ = LF;\n    }\n    if (r->headers_out.content_type.len) {\n        b->last = ngx_cpymem(b->last, "Content-Type: ",\n                             sizeof("Content-Type: ") - 1);\n        p = b->last;\n        b->last = ngx_copy(b->last, r->headers_out.content_type.data,\n                           r->headers_out.content_type.len);\n        if (r->headers_out.content_type_len == r->headers_out.content_type.len\n            && r->headers_out.charset.len)\n        {\n            b->last = ngx_cpymem(b->last, "; charset=",\n                                 sizeof("; charset=") - 1);\n            b->last = ngx_copy(b->last, r->headers_out.charset.data,\n                               r->headers_out.charset.len);\n            r->headers_out.content_type.len = b->last - p;\n            r->headers_out.content_type.data = p;\n        }\n        *b->last++ = CR; *b->last++ = LF;\n    }\n    if (r->headers_out.content_length == NULL\n        && r->headers_out.content_length_n >= 0)\n    {\n        b->last = ngx_sprintf(b->last, "Content-Length: %O" CRLF,\n                              r->headers_out.content_length_n);\n    }\n    if (r->headers_out.last_modified == NULL\n        && r->headers_out.last_modified_time != -1)\n    {\n        b->last = ngx_cpymem(b->last, "Last-Modified: ",\n                             sizeof("Last-Modified: ") - 1);\n        b->last = ngx_http_time(b->last, r->headers_out.last_modified_time);\n        *b->last++ = CR; *b->last++ = LF;\n    }\n    if (host.data) {\n        p = b->last + sizeof("Location: ") - 1;\n        b->last = ngx_cpymem(b->last, "Location: http",\n                             sizeof("Location: http") - 1);\n#if (NGX_HTTP_SSL)\n        if (r->connection->ssl) {\n            *b->last++ =\'s\';\n        }\n#endif\n        *b->last++ = \':\'; *b->last++ = \'/\'; *b->last++ = \'/\';\n        b->last = ngx_copy(b->last, host.data, host.len);\n        if (port) {\n            b->last = ngx_sprintf(b->last, ":%ui", port);\n        }\n        b->last = ngx_copy(b->last, r->headers_out.location->value.data,\n                           r->headers_out.location->value.len);\n        r->headers_out.location->value.len = b->last - p;\n        r->headers_out.location->value.data = p;\n        r->headers_out.location->key.len = sizeof("Location: ") - 1;\n        r->headers_out.location->key.data = (u_char *) "Location: ";\n        *b->last++ = CR; *b->last++ = LF;\n    }\n    if (r->chunked) {\n        b->last = ngx_cpymem(b->last, "Transfer-Encoding: chunked" CRLF,\n                             sizeof("Transfer-Encoding: chunked" CRLF) - 1);\n    }\n    if (r->keepalive) {\n        b->last = ngx_cpymem(b->last, "Connection: keep-alive" CRLF,\n                             sizeof("Connection: keep-alive" CRLF) - 1);\n        if (clcf->keepalive_header) {\n            b->last = ngx_sprintf(b->last, "Keep-Alive: timeout=%T" CRLF,\n                                  clcf->keepalive_header);\n        }\n    } else {\n        b->last = ngx_cpymem(b->last, "Connection: close" CRLF,\n                             sizeof("Connection: close" CRLF) - 1);\n    }\n#if (NGX_HTTP_GZIP)\n    if (r->gzip && clcf->gzip_vary) {\n        b->last = ngx_cpymem(b->last, "Vary: Accept-Encoding" CRLF,\n                             sizeof("Vary: Accept-Encoding" CRLF) - 1);\n    }\n#endif\n    part = &r->headers_out.headers.part;\n    header = part->elts;\n    for (i = 0;  ; i++) {\n        if (i >= part->nelts) {\n            if (part->next == NULL) {\n                break;\n            }\n            part = part->next;\n            header = part->elts;\n            i = 0;\n        }\n        if (header[i].hash == 0) {\n            continue;\n        }\n        b->last = ngx_copy(b->last, header[i].key.data, header[i].key.len);\n        *b->last++ = \':\'; *b->last++ = \' \';\n        b->last = ngx_copy(b->last, header[i].value.data, header[i].value.len);\n        *b->last++ = CR; *b->last++ = LF;\n    }\n    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                   "%*s", (size_t) (b->last - b->pos), b->pos);\n    *b->last++ = CR; *b->last++ = LF;\n    r->header_size = b->last - b->pos;\n    if (r->header_only) {\n        b->last_buf = 1;\n    }\n    out.buf = b;\n    out.next = NULL;\n    return ngx_http_write_filter(r, &out);\n}', 'ngx_buf_t *\nngx_create_temp_buf(ngx_pool_t *pool, size_t size)\n{\n    ngx_buf_t *b;\n    b = ngx_calloc_buf(pool);\n    if (b == NULL) {\n        return NULL;\n    }\n    b->start = ngx_palloc(pool, size);\n    if (b->start == NULL) {\n        return NULL;\n    }\n    b->pos = b->start;\n    b->last = b->start;\n    b->end = b->last + size;\n    b->temporary = 1;\n    return b;\n}', 'void *\nngx_palloc(ngx_pool_t *pool, size_t size)\n{\n    u_char      *m;\n    ngx_pool_t  *p;\n    if (size <= pool->max) {\n        p = pool->current;\n        do {\n            m = ngx_align_ptr(p->d.last, NGX_ALIGNMENT);\n            if ((size_t) (p->d.end - m) >= size) {\n                p->d.last = m + size;\n                return m;\n            }\n            p = p->d.next;\n        } while (p);\n        return ngx_palloc_block(pool, size);\n    }\n    return ngx_palloc_large(pool, size);\n}']