summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2012-11-26 18:00:14 +0000
committerMaxim Dounin <mdounin@mdounin.ru>2012-11-26 18:00:14 +0000
commitc4a4a6a5d8f5f110d2f8203052dc1861aedb061f (patch)
tree26014d77994da5852ad0aef751ee492fdd08e327
parent61feb90d74b9373a9089a09bbbb8c04629672d4f (diff)
downloadnginx-c4a4a6a5d8f5f110d2f8203052dc1861aedb061f.tar.gz
nginx-c4a4a6a5d8f5f110d2f8203052dc1861aedb061f.tar.bz2
Request body: improved handling of incorrect chunked request body.
While discarding chunked request body in some cases after detecting request body corruption no error was returned, while it was possible to correctly return 400 Bad Request. If error is detected too late, make sure to properly close connection. Additionally, in ngx_http_special_response_handler() don't return body of 500 Internal Server Error to a client if ngx_http_discard_request_body() fails, but disable keepalive and continue.
-rw-r--r--src/http/ngx_http_request_body.c19
-rw-r--r--src/http/ngx_http_special_response.c2
2 files changed, 16 insertions, 5 deletions
diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c
index 90da11005..0b2f89ff5 100644
--- a/src/http/ngx_http_request_body.c
+++ b/src/http/ngx_http_request_body.c
@@ -471,12 +471,18 @@ ngx_http_discard_request_body(ngx_http_request_t *r)
}
}
- if (ngx_http_read_discarded_request_body(r) == NGX_OK) {
+ rc = ngx_http_read_discarded_request_body(r);
+
+ if (rc == NGX_OK) {
r->lingering_close = 0;
return NGX_OK;
}
- /* == NGX_AGAIN */
+ if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
+ return rc;
+ }
+
+ /* rc == NGX_AGAIN */
r->read_event_handler = ngx_http_discarded_request_body_handler;
@@ -533,6 +539,12 @@ ngx_http_discarded_request_body_handler(ngx_http_request_t *r)
return;
}
+ if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
+ c->error = 1;
+ ngx_http_finalize_request(r, NGX_ERROR);
+ return;
+ }
+
/* rc == NGX_AGAIN */
if (ngx_handle_read_event(rev, 0) != NGX_OK) {
@@ -606,8 +618,7 @@ ngx_http_read_discarded_request_body(ngx_http_request_t *r)
rc = ngx_http_discard_request_body_filter(r, &b);
if (rc != NGX_OK) {
- r->connection->error = 1;
- return NGX_OK;
+ return rc;
}
}
}
diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c
index 318b52be2..875c24d9c 100644
--- a/src/http/ngx_http_special_response.c
+++ b/src/http/ngx_http_special_response.c
@@ -421,7 +421,7 @@ ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
r->expect_tested = 1;
if (ngx_http_discard_request_body(r) != NGX_OK) {
- error = NGX_HTTP_INTERNAL_SERVER_ERROR;
+ r->keepalive = 0;
}
if (clcf->msie_refresh