]> granicus.if.org Git - libevent/commitdiff
Reject overlong http requests early when Expect:100-continue is set
authorConstantine Verutin <cverutin@gmail.com>
Tue, 7 Dec 2010 16:43:52 +0000 (11:43 -0500)
committerNick Mathewson <nickm@torproject.org>
Tue, 7 Dec 2010 16:43:52 +0000 (11:43 -0500)
http.c
include/event2/http.h
test/regress_http.c

diff --git a/http.c b/http.c
index 8bc6db12f630e4f2bbdf0dbe2dd1a639f0f42522..70de30ac1163bfdb2167422ca2d87513868c34df 100644 (file)
--- a/http.c
+++ b/http.c
@@ -1846,6 +1846,11 @@ evhttp_get_body(struct evhttp_connection *evcon, struct evhttp_request *req)
                                   no, we should respond with an error. For
                                   now, just optimistically tell the client to
                                   send their message body. */
+                               if (req->ntoread > req->evcon->max_body_size) {
+                                       evhttp_send_error(req, HTTP_ENTITYTOOLARGE,
+                                                         NULL);
+                                       return;
+                               }
                                if (!evbuffer_get_length(bufferevent_get_input(evcon->bufev)))
                                        evhttp_send_continue(evcon, req);
                        } else {
index 5492ac385b3599bcfaad4b8807f21e2fa4bd6a61..69f32ef8738b8bc4d60d9780300c18f3d1ea834f 100644 (file)
@@ -58,6 +58,7 @@ struct event_base;
 #define HTTP_BADREQUEST                400     /**< invalid http request was made */
 #define HTTP_NOTFOUND          404     /**< could not find content for uri */
 #define HTTP_BADMETHOD         405     /**< method not allowed for this uri */
+#define HTTP_ENTITYTOOLARGE    413     /**<  */
 #define HTTP_EXPECTATIONFAILED 417     /**< we can't handle this expectation */
 #define HTTP_INTERNAL           500     /**< internal error */
 #define HTTP_NOTIMPLEMENTED     501     /**< not implemented */
index 0d8395bc3b5ac6fa01e9784db1019a55d0560abb..349dbee297e5745b00e06becf3e51cee8227b5b4 100644 (file)
@@ -3273,6 +3273,15 @@ end:
        event_base_loopexit(arg, NULL);
 }
 
+static void
+http_large_entity_test_done(struct evhttp_request *req, void *arg)
+{
+       tt_assert(req);
+       tt_int_op(evhttp_request_get_response_code(req), ==, HTTP_ENTITYTOOLARGE);
+end:
+       event_base_loopexit(arg, NULL);
+}
+
 static void
 http_data_length_constraints_test(void *arg)
 {
@@ -3331,6 +3340,15 @@ http_data_length_constraints_test(void *arg)
        }
        event_base_dispatch(data->base);
 
+       req = evhttp_request_new(http_large_entity_test_done, data->base);
+       evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
+       evhttp_add_header(evhttp_request_get_output_headers(req), "Expect", "100-continue");
+       evbuffer_add_printf(evhttp_request_get_output_buffer(req), "%s", long_str);
+       if (evhttp_make_request(evcon, req, EVHTTP_REQ_POST, "/") == -1) {
+               tt_abort_msg("Couldn't make request");
+       }
+       event_base_dispatch(data->base);
+        
        test_ok = 1;
  end:
        if (evcon)