From: Ryan Bloom Date: Wed, 1 Nov 2000 06:02:22 +0000 (+0000) Subject: Fix canned-errors and OPTIONS requests, so that we don't allocate 8k X-Git-Tag: APACHE_2_0_ALPHA_8~212 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=223355decb3085b361b16d4baa82da6e7771f7ad;p=apache Fix canned-errors and OPTIONS requests, so that we don't allocate 8k for the headers. We count the number of bytes we expect to get and only allocation that many bytes. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@86782 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/http/http_protocol.c b/modules/http/http_protocol.c index 507a1b2aed..34c834ab3f 100644 --- a/modules/http/http_protocol.c +++ b/modules/http/http_protocol.c @@ -2109,8 +2109,14 @@ int ap_send_http_options(request_rec *r) if (r->assbackwards) return DECLINED; - buff = apr_pcalloc(r->pool, HUGE_STRING_LEN); - len = HUGE_STRING_LEN; + apr_table_do((int (*) (void *, const char *, const char *)) compute_header_len, + (void *) &len, r->headers_out, NULL); + + /* Need to add a fudge factor so that the CRLF at the end of the headers + * and the basic http headers don't overflow this buffer. + */ + len += strlen(ap_get_server_version()) + 100; + buff = apr_pcalloc(r->pool, len); ap_basic_http_header(r, buff); apr_table_setn(r->headers_out, "Content-Length", "0"); @@ -2128,7 +2134,7 @@ int ap_send_http_options(request_rec *r) ap_bsetopt(r->connection->client, BO_BYTECT, &zero); bb = ap_brigade_create(r->pool); - b = ap_bucket_create_pool(buff, len, r->pool); + b = ap_bucket_create_pool(buff, strlen(buff), r->pool); AP_BRIGADE_INSERT_TAIL(bb, b); ap_pass_brigade(r->output_filters, bb); @@ -3243,7 +3249,7 @@ AP_DECLARE(void) ap_send_error_response(request_rec *r, int recursive_error) * message body. Note that being assbackwards here is not an option. */ if (status == HTTP_NOT_MODIFIED) { - char *buff = apr_pcalloc(r->pool, HUGE_STRING_LEN); + char *buff; header_struct h; ap_bucket *e; ap_bucket_brigade *bb; @@ -3252,7 +3258,15 @@ AP_DECLARE(void) ap_send_error_response(request_rec *r, int recursive_error) r->headers_out = apr_overlay_tables(r->pool, r->err_headers_out, r->headers_out); - e = ap_bucket_create_pool(buff, HUGE_STRING_LEN, r->pool); + apr_table_do((int (*) (void *, const char *, const char *)) compute_header_len, + (void *) &len, r->headers_out, NULL); + + /* Need to add a fudge factor so that the CRLF at the end of the headers + * and the basic http headers don't overflow this buffer. + */ + len += strlen(ap_get_server_version()) + 100; + buff = apr_pcalloc(r->pool, len); + e = ap_bucket_create_pool(buff, len, r->pool); ap_basic_http_header(r, buff); ap_set_keepalive(r); @@ -3274,7 +3288,7 @@ AP_DECLARE(void) ap_send_error_response(request_rec *r, int recursive_error) NULL); terminate_header(buff); - + bb = ap_brigade_create(r->pool); AP_BRIGADE_INSERT_HEAD(bb, e); ap_pass_brigade(r->connection->output_filters, bb);