modules/http/http_protocol.c:898: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned64 by call to `ap_get_mime_headers`.

modules/http/http_protocol.c:898:17: Call
896.                 /* Handle trailers by calling ap_get_mime_headers again! */
897.                 ctx->state = BODY_NONE;
898.                 ap_get_mime_headers(f->r);
                     ^
899.                 e = apr_bucket_eos_create(f->c->bucket_alloc);
900.                 APR_BRIGADE_INSERT_TAIL(b, e);

server/protocol.c:828:1: Parameter `r->server->limit_req_fieldsize`
  826. }
  827. 
  828. AP_DECLARE(void) ap_get_mime_headers(request_rec *r)
       ^
  829. {
  830.     apr_bucket_brigade *tmp_bb;

server/protocol.c:832:5: Call
  830.     apr_bucket_brigade *tmp_bb;
  831.     tmp_bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
  832.     ap_get_mime_headers_core(r, tmp_bb);
           ^
  833.     apr_brigade_destroy(tmp_bb);
  834. }

server/protocol.c:666:1: Parameter `r->server->limit_req_fieldsize`
    664. }
    665. 
    666. AP_DECLARE(void) ap_get_mime_headers_core(request_rec *r, apr_bucket_brigade *bb)
         ^
    667. {
    668.     char *last_field = NULL;

server/protocol.c:686:14: Call
    684. 
    685.         field = NULL;
    686.         rv = ap_rgetline(&field, r->server->limit_req_fieldsize + 2,
                      ^
    687.                          &len, r, 0, bb);
    688. 

server/protocol.c:202:1: <LHS trace>
200.  *        or a full buffer, that's considered an error.
201.  */
202. AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
     ^
203.                                           apr_size_t *read, request_rec *r,
204.                                           int fold, apr_bucket_brigade *bb)

server/protocol.c:202:1: Parameter `n`
      200.  *        or a full buffer, that's considered an error.
      201.  */
      202. AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
           ^
      203.                                           apr_size_t *read, request_rec *r,
      204.                                           int fold, apr_bucket_brigade *bb)

server/protocol.c:392:21: Binary operation: ([0, +oo] - 1):unsigned64 by call to `ap_get_mime_headers` 
      390.                     *read = n;
      391.                     /* ensure this string is terminated */
      392.                     (*s)[n-1] = '\0';
                               ^
      393.                     return APR_ENOSPC;
      394.                 }

AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
                                          apr_size_t *read, request_rec *r,
                                          int fold, apr_bucket_brigade *bb)
{
    apr_status_t rv;
    apr_bucket *e;
    apr_size_t bytes_handled = 0, current_alloc = 0;
    char *pos, *last_char = *s;
    int do_alloc = (*s == NULL), saw_eos = 0;
    for (;;) {
        apr_brigade_cleanup(bb);
        rv = ap_get_brigade(r->input_filters, bb, AP_MODE_GETLINE,
                            APR_BLOCK_READ, 0);
        if (rv != APR_SUCCESS) {
            return rv;
        }
        if (APR_BRIGADE_EMPTY(bb)) {
            return APR_EGENERAL;
        }
        for (e = APR_BRIGADE_FIRST(bb);
             e != APR_BRIGADE_SENTINEL(bb);
             e = APR_BUCKET_NEXT(e))
        {
            const char *str;
            apr_size_t len;
            if (APR_BUCKET_IS_EOS(e)) {
                saw_eos = 1;
                break;
            }
            rv = apr_bucket_read(e, &str, &len, APR_BLOCK_READ);
            if (rv != APR_SUCCESS) {
                return rv;
            }
            if (len == 0) {
                continue;
            }
            if (n < bytes_handled + len) {
                *read = bytes_handled;
                if (*s) {
                    if (bytes_handled > 0) {
                        (*s)[bytes_handled-1] = '\0';
                    }
                    else {
                        (*s)[0] = '\0';
                    }
                }
                return APR_ENOSPC;
            }
            if (do_alloc) {
                if (!*s) {
                    current_alloc = len;
                    if (current_alloc < MIN_LINE_ALLOC) {
                        current_alloc = MIN_LINE_ALLOC;
                    }
                    *s = apr_palloc(r->pool, current_alloc);
                }
                else if (bytes_handled + len > current_alloc) {
                    apr_size_t new_size = current_alloc * 2;
                    char *new_buffer;
                    if (bytes_handled + len > new_size) {
                        new_size = (bytes_handled + len) * 2;
                    }
                    new_buffer = apr_palloc(r->pool, new_size);
                    memcpy(new_buffer, *s, bytes_handled);
                    current_alloc = new_size;
                    *s = new_buffer;
                }
            }
            pos = *s + bytes_handled;
            memcpy(pos, str, len);
            last_char = pos + len - 1;
            bytes_handled += len;
        }
        if (last_char && (*last_char == APR_ASCII_LF)) {
            break;
        }
    }
    pos = last_char;
    if (pos > *s && *(pos - 1) == APR_ASCII_CR) {
        --pos;
    }
    while (pos > ((*s) + 1)
           && (*(pos - 1) == APR_ASCII_BLANK || *(pos - 1) == APR_ASCII_TAB)) {
        --pos;
    }
    *pos = '\0';
    last_char = pos;
    bytes_handled = pos - *s;
    if (fold && bytes_handled && !saw_eos) {
        for (;;) {
            const char *str;
            apr_size_t len;
            char c;
            apr_brigade_cleanup(bb);
            rv = ap_get_brigade(r->input_filters, bb, AP_MODE_SPECULATIVE,
                                APR_BLOCK_READ, 1);
            if (rv != APR_SUCCESS) {
                return rv;
            }
            if (APR_BRIGADE_EMPTY(bb)) {
                break;
            }
            e = APR_BRIGADE_FIRST(bb);
            if (APR_BUCKET_IS_EOS(e)) {
                break;
            }
            rv = apr_bucket_read(e, &str, &len, APR_BLOCK_READ);
            if (rv != APR_SUCCESS) {
                apr_brigade_cleanup(bb);
                return rv;
            }
            c = *str;
            if (c == APR_ASCII_BLANK || c == APR_ASCII_TAB) {
                if (bytes_handled >= n) {
                    *read = n;
                    (*s)[n-1] = '\0';
                    return APR_ENOSPC;
                }
                else {
                    apr_size_t next_size, next_len;
                    char *tmp;
                    if (do_alloc) {
                        tmp = NULL;
                    } else {
                        tmp = last_char;
                    }
                    next_size = n - bytes_handled;
                    rv = ap_rgetline_core(&tmp, next_size,
                                          &next_len, r, 0, bb);
                    if (rv != APR_SUCCESS) {
                        return rv;
                    }
                    if (do_alloc && next_len > 0) {
                        char *new_buffer;
                        apr_size_t new_size = bytes_handled + next_len + 1;
                        new_buffer = apr_palloc(r->pool, new_size);
                        memcpy(new_buffer, *s, bytes_handled);
                        memcpy(new_buffer + bytes_handled, tmp, next_len + 1);
                        *s = new_buffer;
                    }
                    last_char += next_len;
                    bytes_handled += next_len;
                }
            }
            else {
                break;
            }
        }
    }
    *read = bytes_handled;
    return APR_SUCCESS;
}
['apr_status_t ap_http_filter(ap_filter_t *f, apr_bucket_brigade *b,\n                            ap_input_mode_t mode, apr_read_type_e block,\n                            apr_off_t readbytes)\n{\n    apr_bucket *e;\n    http_ctx_t *ctx = f->ctx;\n    apr_status_t rv;\n    apr_off_t totalread;\n    if (mode != AP_MODE_READBYTES && mode != AP_MODE_GETLINE) {\n        return ap_get_brigade(f->next, b, mode, block, readbytes);\n    }\n    if (!ctx) {\n        const char *tenc, *lenp;\n        f->ctx = ctx = apr_palloc(f->r->pool, sizeof(*ctx));\n        ctx->state = BODY_NONE;\n        ctx->remaining = 0;\n        ctx->limit_used = 0;\n        ctx->eos_sent = 0;\n        if (!f->r->proxyreq) {\n            ctx->limit = ap_get_limit_req_body(f->r);\n        }\n        else {\n            ctx->limit = 0;\n        }\n        tenc = apr_table_get(f->r->headers_in, "Transfer-Encoding");\n        lenp = apr_table_get(f->r->headers_in, "Content-Length");\n        if (tenc) {\n            if (!strcasecmp(tenc, "chunked")) {\n                ctx->state = BODY_CHUNK;\n            }\n        }\n        else if (lenp) {\n            char *endstr;\n            ctx->state = BODY_LENGTH;\n            errno = 0;\n            if (apr_strtoff(&ctx->remaining, lenp, &endstr, 10)\n                || *endstr || ctx->remaining < 0) {\n                apr_bucket_brigade *bb;\n                ctx->remaining = 0;\n                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r,\n                              "Invalid Content-Length");\n                bb = apr_brigade_create(f->r->pool, f->c->bucket_alloc);\n                e = ap_bucket_error_create(HTTP_REQUEST_ENTITY_TOO_LARGE, NULL,\n                                           f->r->pool, f->c->bucket_alloc);\n                APR_BRIGADE_INSERT_TAIL(bb, e);\n                e = apr_bucket_eos_create(f->c->bucket_alloc);\n                APR_BRIGADE_INSERT_TAIL(bb, e);\n                ctx->eos_sent = 1;\n                return ap_pass_brigade(f->r->output_filters, bb);\n            }\n            if (ctx->limit && ctx->limit < ctx->remaining) {\n                apr_bucket_brigade *bb;\n                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r,\n                          "Requested content-length of %" APR_OFF_T_FMT\n                          " is larger than the configured limit"\n                          " of %" APR_OFF_T_FMT, ctx->remaining, ctx->limit);\n                bb = apr_brigade_create(f->r->pool, f->c->bucket_alloc);\n                e = ap_bucket_error_create(HTTP_REQUEST_ENTITY_TOO_LARGE, NULL,\n                                           f->r->pool, f->c->bucket_alloc);\n                APR_BRIGADE_INSERT_TAIL(bb, e);\n                e = apr_bucket_eos_create(f->c->bucket_alloc);\n                APR_BRIGADE_INSERT_TAIL(bb, e);\n                ctx->eos_sent = 1;\n                return ap_pass_brigade(f->r->output_filters, bb);\n            }\n        }\n        if (ctx->state == BODY_NONE && f->r->proxyreq != PROXYREQ_RESPONSE) {\n            e = apr_bucket_eos_create(f->c->bucket_alloc);\n            APR_BRIGADE_INSERT_TAIL(b, e);\n            ctx->eos_sent = 1;\n            return APR_SUCCESS;\n        }\n        if ((ctx->state == BODY_CHUNK ||\n            (ctx->state == BODY_LENGTH && ctx->remaining > 0)) &&\n            f->r->expecting_100 && f->r->proto_num >= HTTP_VERSION(1,1)) {\n            char *tmp;\n            apr_bucket_brigade *bb;\n            tmp = apr_pstrcat(f->r->pool, AP_SERVER_PROTOCOL, " ",\n                              status_lines[0], CRLF CRLF, NULL);\n            bb = apr_brigade_create(f->r->pool, f->c->bucket_alloc);\n            e = apr_bucket_pool_create(tmp, strlen(tmp), f->r->pool,\n                                       f->c->bucket_alloc);\n            APR_BRIGADE_INSERT_HEAD(bb, e);\n            e = apr_bucket_flush_create(f->c->bucket_alloc);\n            APR_BRIGADE_INSERT_TAIL(bb, e);\n            ap_pass_brigade(f->c->output_filters, bb);\n        }\n        if (ctx->state == BODY_CHUNK) {\n            char line[30];\n            apr_bucket_brigade *bb;\n            apr_size_t len = 30;\n            apr_off_t brigade_length;\n            bb = apr_brigade_create(f->r->pool, f->c->bucket_alloc);\n            rv = ap_get_brigade(f->next, bb, AP_MODE_GETLINE,\n                                APR_BLOCK_READ, 0);\n            if (rv == APR_SUCCESS) {\n                rv = apr_brigade_length(bb, 1, &brigade_length);\n                if (rv == APR_SUCCESS\n                    && brigade_length > f->r->server->limit_req_line) {\n                    rv = APR_ENOSPC;\n                }\n                if (rv == APR_SUCCESS) {\n                    rv = apr_brigade_flatten(bb, line, &len);\n                    if (rv == APR_SUCCESS) {\n                        ctx->remaining = get_chunk_size(line);\n                    }\n                }\n            }\n            apr_brigade_cleanup(bb);\n            if (rv != APR_SUCCESS || ctx->remaining < 0) {\n                ctx->remaining = 0;\n                e = ap_bucket_error_create(HTTP_REQUEST_ENTITY_TOO_LARGE, NULL,\n                                           f->r->pool,\n                                           f->c->bucket_alloc);\n                APR_BRIGADE_INSERT_TAIL(bb, e);\n                e = apr_bucket_eos_create(f->c->bucket_alloc);\n                APR_BRIGADE_INSERT_TAIL(bb, e);\n                ctx->eos_sent = 1;\n                return ap_pass_brigade(f->r->output_filters, bb);\n            }\n            if (!ctx->remaining) {\n                ctx->state = BODY_NONE;\n                ap_get_mime_headers(f->r);\n                e = apr_bucket_eos_create(f->c->bucket_alloc);\n                APR_BRIGADE_INSERT_TAIL(b, e);\n                ctx->eos_sent = 1;\n                return APR_SUCCESS;\n            }\n        }\n    }\n    if (ctx->eos_sent) {\n        e = apr_bucket_eos_create(f->c->bucket_alloc);\n        APR_BRIGADE_INSERT_TAIL(b, e);\n        return APR_SUCCESS;\n    }\n    if (!ctx->remaining) {\n        switch (ctx->state) {\n        case BODY_NONE:\n            break;\n        case BODY_LENGTH:\n            e = apr_bucket_eos_create(f->c->bucket_alloc);\n            APR_BRIGADE_INSERT_TAIL(b, e);\n            ctx->eos_sent = 1;\n            return APR_SUCCESS;\n        case BODY_CHUNK:\n            {\n                char line[30];\n                apr_bucket_brigade *bb;\n                apr_size_t len = 30;\n                bb = apr_brigade_create(f->r->pool, f->c->bucket_alloc);\n                rv = ap_get_brigade(f->next, bb, AP_MODE_GETLINE,\n                                    APR_BLOCK_READ, 0);\n                apr_brigade_cleanup(bb);\n                if (rv == APR_SUCCESS) {\n                    rv = ap_get_brigade(f->next, bb, AP_MODE_GETLINE,\n                                        APR_BLOCK_READ, 0);\n                    if (rv == APR_SUCCESS) {\n                        rv = apr_brigade_flatten(bb, line, &len);\n                        if (rv == APR_SUCCESS) {\n                            ctx->remaining = get_chunk_size(line);\n                        }\n                    }\n                    apr_brigade_cleanup(bb);\n                }\n                if (rv != APR_SUCCESS || ctx->remaining < 0) {\n                    ctx->remaining = 0;\n                    e = ap_bucket_error_create(HTTP_REQUEST_ENTITY_TOO_LARGE,\n                                               NULL, f->r->pool,\n                                               f->c->bucket_alloc);\n                    APR_BRIGADE_INSERT_TAIL(bb, e);\n                    e = apr_bucket_eos_create(f->c->bucket_alloc);\n                    APR_BRIGADE_INSERT_TAIL(bb, e);\n                    ctx->eos_sent = 1;\n                    return ap_pass_brigade(f->r->output_filters, bb);\n                }\n                if (!ctx->remaining) {\n                    ctx->state = BODY_NONE;\n                    ap_get_mime_headers(f->r);\n                    e = apr_bucket_eos_create(f->c->bucket_alloc);\n                    APR_BRIGADE_INSERT_TAIL(b, e);\n                    ctx->eos_sent = 1;\n                    return APR_SUCCESS;\n                }\n            }\n            break;\n        }\n    }\n    if (ctx->state == BODY_LENGTH || ctx->state == BODY_CHUNK) {\n        if (ctx->remaining < readbytes) {\n            readbytes = ctx->remaining;\n        }\n        AP_DEBUG_ASSERT(readbytes > 0);\n    }\n    rv = ap_get_brigade(f->next, b, mode, block, readbytes);\n    if (rv != APR_SUCCESS) {\n        return rv;\n    }\n    apr_brigade_length(b, 0, &totalread);\n    AP_DEBUG_ASSERT(totalread >= 0);\n    if (ctx->state != BODY_NONE) {\n        ctx->remaining -= totalread;\n    }\n    if (ctx->state == BODY_LENGTH && ctx->remaining == 0) {\n        e = apr_bucket_eos_create(f->c->bucket_alloc);\n        APR_BRIGADE_INSERT_TAIL(b, e);\n    }\n    if (ctx->limit) {\n        ctx->limit_used += totalread;\n        if (ctx->limit < ctx->limit_used) {\n            apr_bucket_brigade *bb;\n            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r,\n                          "Read content-length of %" APR_OFF_T_FMT\n                          " is larger than the configured limit"\n                          " of %" APR_OFF_T_FMT, ctx->limit_used, ctx->limit);\n            bb = apr_brigade_create(f->r->pool, f->c->bucket_alloc);\n            e = ap_bucket_error_create(HTTP_REQUEST_ENTITY_TOO_LARGE, NULL,\n                                       f->r->pool,\n                                       f->c->bucket_alloc);\n            APR_BRIGADE_INSERT_TAIL(bb, e);\n            e = apr_bucket_eos_create(f->c->bucket_alloc);\n            APR_BRIGADE_INSERT_TAIL(bb, e);\n            ctx->eos_sent = 1;\n            return ap_pass_brigade(f->r->output_filters, bb);\n        }\n    }\n    return APR_SUCCESS;\n}', 'AP_DECLARE(void) ap_get_mime_headers(request_rec *r)\n{\n    apr_bucket_brigade *tmp_bb;\n    tmp_bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);\n    ap_get_mime_headers_core(r, tmp_bb);\n    apr_brigade_destroy(tmp_bb);\n}', 'AP_DECLARE(void) ap_get_mime_headers_core(request_rec *r, apr_bucket_brigade *bb)\n{\n    char *last_field = NULL;\n    apr_size_t last_len = 0;\n    apr_size_t alloc_len = 0;\n    char *field;\n    char *value;\n    apr_size_t len;\n    int fields_read = 0;\n    char *tmp_field;\n    while(1) {\n        apr_status_t rv;\n        int folded = 0;\n        field = NULL;\n        rv = ap_rgetline(&field, r->server->limit_req_fieldsize + 2,\n                         &len, r, 0, bb);\n        if (rv != APR_SUCCESS) {\n            r->status = HTTP_BAD_REQUEST;\n            if (rv == APR_ENOSPC && field) {\n                field[len - 1] = \'\\0\';\n                apr_table_setn(r->notes, "error-notes",\n                               apr_pstrcat(r->pool,\n                                           "Size of a request header field "\n                                           "exceeds server limit.<br />\\n"\n                                           "<pre>\\n",\n                                           ap_escape_html(r->pool, field),\n                                           "</pre>\\n", NULL));\n            }\n            return;\n        }\n        if (last_field != NULL) {\n            if ((len > 0) && ((*field == \'\\t\') || *field == \' \')) {\n                apr_size_t fold_len = last_len + len + 1;\n                if (fold_len > r->server->limit_req_fieldsize + 1) {\n                    r->status = HTTP_BAD_REQUEST;\n                    apr_table_setn(r->notes, "error-notes",\n                                   apr_pstrcat(r->pool,\n                                               "Size of a request header field "\n                                               "after folding "\n                                               "exceeds server limit.<br />\\n"\n                                               "<pre>\\n",\n                                               ap_escape_html(r->pool, last_field),\n                                               "</pre>\\n", NULL));\n                    return;\n                }\n                if (fold_len > alloc_len) {\n                    char *fold_buf;\n                    alloc_len += alloc_len;\n                    if (fold_len > alloc_len) {\n                        alloc_len = fold_len;\n                    }\n                    fold_buf = (char *)apr_palloc(r->pool, alloc_len);\n                    memcpy(fold_buf, last_field, last_len);\n                    last_field = fold_buf;\n                }\n                memcpy(last_field + last_len, field, len +1);\n                last_len += len;\n                folded = 1;\n            }\n            else {\n                if (r->server->limit_req_fields\n                    && (++fields_read > r->server->limit_req_fields)) {\n                    r->status = HTTP_BAD_REQUEST;\n                    apr_table_setn(r->notes, "error-notes",\n                                   "The number of request header fields "\n                                   "exceeds this server\'s limit.");\n                    return;\n                }\n                if (!(value = strchr(last_field, \':\'))) {\n                    r->status = HTTP_BAD_REQUEST;\n                    apr_table_setn(r->notes, "error-notes",\n                                   apr_pstrcat(r->pool,\n                                               "Request header field is "\n                                               "missing \':\' separator.<br />\\n"\n                                               "<pre>\\n",\n                                               ap_escape_html(r->pool,\n                                                              last_field),\n                                               "</pre>\\n", NULL));\n                    return;\n                }\n                *value = \'\\0\';\n                tmp_field = value;\n                ++value;\n                while (*value == \' \' || *value == \'\\t\') {\n                    ++value;\n                }\n                if (tmp_field > last_field) {\n                    --tmp_field;\n                    while ((tmp_field > last_field) &&\n                           (*tmp_field == \' \' || *tmp_field == \'\\t\')) {\n                        --tmp_field;\n                    }\n                    ++tmp_field;\n                    *tmp_field = \'\\0\';\n                }\n                apr_table_addn(r->headers_in, last_field, value);\n                alloc_len = 0;\n            }\n        }\n        if (len == 0) {\n            break;\n        }\n        if (!folded) {\n            last_field = field;\n            last_len = len;\n        }\n    }\n    apr_table_compress(r->headers_in, APR_OVERLAP_TABLES_MERGE);\n}', "AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,\n                                          apr_size_t *read, request_rec *r,\n                                          int fold, apr_bucket_brigade *bb)\n{\n    apr_status_t rv;\n    apr_bucket *e;\n    apr_size_t bytes_handled = 0, current_alloc = 0;\n    char *pos, *last_char = *s;\n    int do_alloc = (*s == NULL), saw_eos = 0;\n    for (;;) {\n        apr_brigade_cleanup(bb);\n        rv = ap_get_brigade(r->input_filters, bb, AP_MODE_GETLINE,\n                            APR_BLOCK_READ, 0);\n        if (rv != APR_SUCCESS) {\n            return rv;\n        }\n        if (APR_BRIGADE_EMPTY(bb)) {\n            return APR_EGENERAL;\n        }\n        for (e = APR_BRIGADE_FIRST(bb);\n             e != APR_BRIGADE_SENTINEL(bb);\n             e = APR_BUCKET_NEXT(e))\n        {\n            const char *str;\n            apr_size_t len;\n            if (APR_BUCKET_IS_EOS(e)) {\n                saw_eos = 1;\n                break;\n            }\n            rv = apr_bucket_read(e, &str, &len, APR_BLOCK_READ);\n            if (rv != APR_SUCCESS) {\n                return rv;\n            }\n            if (len == 0) {\n                continue;\n            }\n            if (n < bytes_handled + len) {\n                *read = bytes_handled;\n                if (*s) {\n                    if (bytes_handled > 0) {\n                        (*s)[bytes_handled-1] = '\\0';\n                    }\n                    else {\n                        (*s)[0] = '\\0';\n                    }\n                }\n                return APR_ENOSPC;\n            }\n            if (do_alloc) {\n                if (!*s) {\n                    current_alloc = len;\n                    if (current_alloc < MIN_LINE_ALLOC) {\n                        current_alloc = MIN_LINE_ALLOC;\n                    }\n                    *s = apr_palloc(r->pool, current_alloc);\n                }\n                else if (bytes_handled + len > current_alloc) {\n                    apr_size_t new_size = current_alloc * 2;\n                    char *new_buffer;\n                    if (bytes_handled + len > new_size) {\n                        new_size = (bytes_handled + len) * 2;\n                    }\n                    new_buffer = apr_palloc(r->pool, new_size);\n                    memcpy(new_buffer, *s, bytes_handled);\n                    current_alloc = new_size;\n                    *s = new_buffer;\n                }\n            }\n            pos = *s + bytes_handled;\n            memcpy(pos, str, len);\n            last_char = pos + len - 1;\n            bytes_handled += len;\n        }\n        if (last_char && (*last_char == APR_ASCII_LF)) {\n            break;\n        }\n    }\n    pos = last_char;\n    if (pos > *s && *(pos - 1) == APR_ASCII_CR) {\n        --pos;\n    }\n    while (pos > ((*s) + 1)\n           && (*(pos - 1) == APR_ASCII_BLANK || *(pos - 1) == APR_ASCII_TAB)) {\n        --pos;\n    }\n    *pos = '\\0';\n    last_char = pos;\n    bytes_handled = pos - *s;\n    if (fold && bytes_handled && !saw_eos) {\n        for (;;) {\n            const char *str;\n            apr_size_t len;\n            char c;\n            apr_brigade_cleanup(bb);\n            rv = ap_get_brigade(r->input_filters, bb, AP_MODE_SPECULATIVE,\n                                APR_BLOCK_READ, 1);\n            if (rv != APR_SUCCESS) {\n                return rv;\n            }\n            if (APR_BRIGADE_EMPTY(bb)) {\n                break;\n            }\n            e = APR_BRIGADE_FIRST(bb);\n            if (APR_BUCKET_IS_EOS(e)) {\n                break;\n            }\n            rv = apr_bucket_read(e, &str, &len, APR_BLOCK_READ);\n            if (rv != APR_SUCCESS) {\n                apr_brigade_cleanup(bb);\n                return rv;\n            }\n            c = *str;\n            if (c == APR_ASCII_BLANK || c == APR_ASCII_TAB) {\n                if (bytes_handled >= n) {\n                    *read = n;\n                    (*s)[n-1] = '\\0';\n                    return APR_ENOSPC;\n                }\n                else {\n                    apr_size_t next_size, next_len;\n                    char *tmp;\n                    if (do_alloc) {\n                        tmp = NULL;\n                    } else {\n                        tmp = last_char;\n                    }\n                    next_size = n - bytes_handled;\n                    rv = ap_rgetline_core(&tmp, next_size,\n                                          &next_len, r, 0, bb);\n                    if (rv != APR_SUCCESS) {\n                        return rv;\n                    }\n                    if (do_alloc && next_len > 0) {\n                        char *new_buffer;\n                        apr_size_t new_size = bytes_handled + next_len + 1;\n                        new_buffer = apr_palloc(r->pool, new_size);\n                        memcpy(new_buffer, *s, bytes_handled);\n                        memcpy(new_buffer + bytes_handled, tmp, next_len + 1);\n                        *s = new_buffer;\n                    }\n                    last_char += next_len;\n                    bytes_handled += next_len;\n                }\n            }\n            else {\n                break;\n            }\n        }\n    }\n    *read = bytes_handled;\n    return APR_SUCCESS;\n}"]