Skip to content

Commit 8b6d55f

Browse files
committed
Merge r1906539 from trunk:
fail on bad header Submitted By: covener Reviewed By: covener, rpluem, gbechis git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1906541 13f79535-47bb-0310-9956-ffa450edef68
1 parent 78a2d92 commit 8b6d55f

2 files changed

Lines changed: 29 additions & 19 deletions

File tree

modules/proxy/mod_proxy_http.c

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ static void process_proxy_header(request_rec *r, proxy_dir_conf *c,
788788
* any sense at all, since we depend on buffer still containing
789789
* what was read by ap_getline() upon return.
790790
*/
791-
static void ap_proxy_read_headers(request_rec *r, request_rec *rr,
791+
static apr_status_t ap_proxy_read_headers(request_rec *r, request_rec *rr,
792792
char *buffer, int size,
793793
conn_rec *c, int *pread_len)
794794
{
@@ -820,19 +820,26 @@ static void ap_proxy_read_headers(request_rec *r, request_rec *rr,
820820
rc = ap_proxygetline(tmp_bb, buffer, size, rr,
821821
AP_GETLINE_FOLD | AP_GETLINE_NOSPC_EOL, &len);
822822

823-
if (len <= 0)
824-
break;
825823

826-
if (APR_STATUS_IS_ENOSPC(rc)) {
827-
/* The header could not fit in the provided buffer, warn.
828-
* XXX: falls through with the truncated header, 5xx instead?
829-
*/
830-
int trunc = (len > 128 ? 128 : len) / 2;
831-
ap_log_rerror(APLOG_MARK, APLOG_WARNING, rc, r, APLOGNO(10124)
832-
"header size is over the limit allowed by "
833-
"ResponseFieldSize (%d bytes). "
834-
"Bad response header: '%.*s[...]%s'",
835-
size, trunc, buffer, buffer + len - trunc);
824+
if (rc != APR_SUCCESS) {
825+
if (APR_STATUS_IS_ENOSPC(rc)) {
826+
int trunc = (len > 128 ? 128 : len) / 2;
827+
ap_log_rerror(APLOG_MARK, APLOG_WARNING, rc, r, APLOGNO(10124)
828+
"header size is over the limit allowed by "
829+
"ResponseFieldSize (%d bytes). "
830+
"Bad response header: '%.*s[...]%s'",
831+
size, trunc, buffer, buffer + len - trunc);
832+
}
833+
else {
834+
ap_log_rerror(APLOG_MARK, APLOG_WARNING, rc, r, APLOGNO(10404)
835+
"Error reading headers from backend");
836+
}
837+
r->headers_out = NULL;
838+
return rc;
839+
}
840+
841+
if (len <= 0) {
842+
break;
836843
}
837844
else {
838845
ap_log_rerror(APLOG_MARK, APLOG_TRACE4, 0, r, "%s", buffer);
@@ -855,7 +862,7 @@ static void ap_proxy_read_headers(request_rec *r, request_rec *rr,
855862
if (psc->badopt == bad_error) {
856863
/* Nope, it wasn't even an extra HTTP header. Give up. */
857864
r->headers_out = NULL;
858-
return;
865+
return APR_EINVAL;
859866
}
860867
else if (psc->badopt == bad_body) {
861868
/* if we've already started loading headers_out, then
@@ -869,13 +876,13 @@ static void ap_proxy_read_headers(request_rec *r, request_rec *rr,
869876
"in headers returned by %s (%s)",
870877
r->uri, r->method);
871878
*pread_len = len;
872-
return;
879+
return APR_SUCCESS;
873880
}
874881
else {
875882
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(01099)
876883
"No HTTP headers returned by %s (%s)",
877884
r->uri, r->method);
878-
return;
885+
return APR_SUCCESS;
879886
}
880887
}
881888
}
@@ -905,6 +912,7 @@ static void ap_proxy_read_headers(request_rec *r, request_rec *rr,
905912
process_proxy_header(r, dconf, buffer, value);
906913
saw_headers = 1;
907914
}
915+
return APR_SUCCESS;
908916
}
909917

910918

@@ -1218,10 +1226,10 @@ int ap_proxy_http_process_response(proxy_http_req_t *req)
12181226
"Set-Cookie", NULL);
12191227

12201228
/* shove the headers direct into r->headers_out */
1221-
ap_proxy_read_headers(r, backend->r, buffer, response_field_size,
1222-
origin, &pread_len);
1229+
rc = ap_proxy_read_headers(r, backend->r, buffer, response_field_size,
1230+
origin, &pread_len);
12231231

1224-
if (r->headers_out == NULL) {
1232+
if (rc != APR_SUCCESS || r->headers_out == NULL) {
12251233
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(01106)
12261234
"bad HTTP/%d.%d header returned by %s (%s)",
12271235
major, minor, r->uri, r->method);

server/protocol.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
508508
/* PR#43039: We shouldn't accept NULL bytes within the line */
509509
bytes_handled = strlen(*s);
510510
if (bytes_handled < *read) {
511+
ap_log_data(APLOG_MARK, APLOG_DEBUG, ap_server_conf,
512+
"NULL bytes in header", *s, *read, 0);
511513
*read = bytes_handled;
512514
if (rv == APR_SUCCESS) {
513515
rv = APR_EINVAL;

0 commit comments

Comments
 (0)