Changes to the evhttp_connection_set_max_* functions in `http.c'. Changes to the evhttp_set_max_* functions in `http.c'. Check if the `evhttp_new_object' function in `http.c' returns NULL. Changes to the `evhttp_maybe_add_content_length_header' function in `http.c'. Correct some `evbuffer_get_length' signedness typos in `http.c'.
http.c | 70 ++++++++++++++++++++++++------------------------ include/event2/http.h | 8 +++--- 2 files changed, 39 insertions(+), 39 deletions(-) Compiles and passes `regress', but not tested otherwise. PS: Is it best to post to the list or the tracker?
From fb6efc292ce3bc574ce37281f4d7c41aafc95013 Mon Sep 17 00:00:00 2001 From: Mansour Moufid <mansourmou...@gmail.com> Date: Fri, 27 May 2011 18:06:35 -0400 Subject: [PATCH 1/5] Changes to the evhttp_connection_set_max_* functions in `http.c'. The `max_headers_size' element of an `evhttp_connection' struct is defined as type size_t in `http-internal.h'. The `evhttp_connection_set_max_headers_size' function parameter `new_max_headers_size' was of type ev_ssize_t; this function then checked for negative values, in which case it assigned a value of EV_SIZE_MAX. Just set it directly. (If anything, check for zero.) The `max_body_size' element of an `evhttp_connection' struct is defined as type ev_uint64_t in `http-internal.h'. The `evhttp_connection_set_max_body_size' function parameter `new_max_body_size' was of type ev_ssize_t; this function then checked for negative values, in which case it assigned a value of EV_UINT64_MAX. Again, check for zero and assign directly. Then use: if (n > EV_SIZE_MAX) n = EV_SIZE_MAX; evhttp_connection_set_max_headers_size(foo, n); if (n > EV_UINT64_MAX) n = EV_UINT64_MAX; evhttp_connection_set_max_body_size(foo, n); But these functions aren't used anywhere I can see... --- http.c | 17 +++++++---------- include/event2/http.h | 4 ++-- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/http.c b/http.c index fed40c3..87c554d 100644 --- a/http.c +++ b/http.c @@ -625,21 +625,18 @@ evhttp_make_header(struct evhttp_connection *evcon, struct evhttp_request *req) void evhttp_connection_set_max_headers_size(struct evhttp_connection *evcon, - ev_ssize_t new_max_headers_size) + size_t new_max_headers_size) { - if (new_max_headers_size<0) - evcon->max_headers_size = EV_SIZE_MAX; - else - evcon->max_headers_size = new_max_headers_size; + EVUTIL_ASSERT(new_max_headers_size != 0); + evcon->max_headers_size = new_max_headers_size; } + void evhttp_connection_set_max_body_size(struct evhttp_connection* evcon, - ev_ssize_t new_max_body_size) + ev_uint64_t new_max_body_size) { - if (new_max_body_size<0) - evcon->max_body_size = EV_UINT64_MAX; - else - evcon->max_body_size = new_max_body_size; + EVUTIL_ASSERT(new_max_body_size != 0); + evcon->max_body_size = new_max_body_size; } static int diff --git a/include/event2/http.h b/include/event2/http.h index 793e2b8..aab0bf4 100644 --- a/include/event2/http.h +++ b/include/event2/http.h @@ -460,10 +460,10 @@ struct evhttp_connection *evhttp_request_get_connection(struct evhttp_request *r struct event_base *evhttp_connection_get_base(struct evhttp_connection *req); void evhttp_connection_set_max_headers_size(struct evhttp_connection *evcon, - ev_ssize_t new_max_headers_size); + size_t new_max_headers_size); void evhttp_connection_set_max_body_size(struct evhttp_connection* evcon, - ev_ssize_t new_max_body_size); + ev_uint64_t new_max_body_size); /** Frees an http connection */ void evhttp_connection_free(struct evhttp_connection *evcon); -- 1.7.1
From 0bc56b3d4132dd4920685b0d17bf86fc979bc4a0 Mon Sep 17 00:00:00 2001 From: Mansour Moufid <mansourmou...@gmail.com> Date: Fri, 27 May 2011 18:35:28 -0400 Subject: [PATCH 2/5] Changes to the evhttp_set_max_* functions in `http.c'. Modify the `evhttp_set_max_headers_size' and `evhttp_set_max_body_size' functions, similarly to the previous commit. --- http.c | 18 +++++++----------- include/event2/http.h | 4 ++-- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/http.c b/http.c index 87c554d..9100263 100644 --- a/http.c +++ b/http.c @@ -3252,7 +3252,7 @@ evhttp_new_object(void) evutil_timerclear(&http->timeout); evhttp_set_max_headers_size(http, EV_SIZE_MAX); - evhttp_set_max_body_size(http, EV_SIZE_MAX); + evhttp_set_max_body_size(http, EV_UINT64_MAX); evhttp_set_allowed_methods(http, EVHTTP_REQ_GET | EVHTTP_REQ_POST | @@ -3436,21 +3436,17 @@ evhttp_set_timeout_tv(struct evhttp* http, const struct timeval* tv) } void -evhttp_set_max_headers_size(struct evhttp* http, ev_ssize_t max_headers_size) +evhttp_set_max_headers_size(struct evhttp* http, size_t max_headers_size) { - if (max_headers_size < 0) - http->default_max_headers_size = EV_SIZE_MAX; - else - http->default_max_headers_size = max_headers_size; + EVUTIL_ASSERT(max_headers_size != 0); + http->default_max_headers_size = max_headers_size; } void -evhttp_set_max_body_size(struct evhttp* http, ev_ssize_t max_body_size) +evhttp_set_max_body_size(struct evhttp* http, ev_uint64_t max_body_size) { - if (max_body_size < 0) - http->default_max_body_size = EV_UINT64_MAX; - else - http->default_max_body_size = max_body_size; + EVUTIL_ASSERT(max_body_size != 0); + http->default_max_body_size = max_body_size; } void diff --git a/include/event2/http.h b/include/event2/http.h index aab0bf4..5d73670 100644 --- a/include/event2/http.h +++ b/include/event2/http.h @@ -187,9 +187,9 @@ evutil_socket_t evhttp_bound_socket_get_fd(struct evhttp_bound_socket *bound_soc void evhttp_free(struct evhttp* http); /** XXX Document. */ -void evhttp_set_max_headers_size(struct evhttp* http, ev_ssize_t max_headers_size); +void evhttp_set_max_headers_size(struct evhttp* http, size_t max_headers_size); /** XXX Document. */ -void evhttp_set_max_body_size(struct evhttp* http, ev_ssize_t max_body_size); +void evhttp_set_max_body_size(struct evhttp* http, ev_uint64_t max_body_size); /** Sets the what HTTP methods are supported in requests accepted by this -- 1.7.1
From 3bbd975af7b04832f503b8cd499739b4f77f6f60 Mon Sep 17 00:00:00 2001 From: Mansour Moufid <mansourmou...@gmail.com> Date: Fri, 27 May 2011 18:40:31 -0400 Subject: [PATCH 3/5] Check if the `evhttp_new_object' function in `http.c' returns NULL. --- http.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/http.c b/http.c index 9100263..2f6e50a 100644 --- a/http.c +++ b/http.c @@ -3272,8 +3272,11 @@ evhttp_new_object(void) struct evhttp * evhttp_new(struct event_base *base) { - struct evhttp *http = evhttp_new_object(); + struct evhttp *http = NULL; + http = evhttp_new_object(); + if (http == NULL) + return (NULL); http->base = base; return (http); @@ -3286,8 +3289,11 @@ evhttp_new(struct event_base *base) struct evhttp * evhttp_start(const char *address, unsigned short port) { - struct evhttp *http = evhttp_new_object(); + struct evhttp *http = NULL; + http = evhttp_new_object(); + if (http == NULL) + return (NULL); if (evhttp_bind_socket(http, address, port) == -1) { mm_free(http); return (NULL); -- 1.7.1
From 850e17aa2956400dc1dd7c0878240e28be2797ba Mon Sep 17 00:00:00 2001 From: Mansour Moufid <mansourmou...@gmail.com> Date: Fri, 27 May 2011 18:45:57 -0400 Subject: [PATCH 4/5] Changes to the `evhttp_maybe_add_content_length_header' function in `http.c'. Change the `content_length' parameter of the `evhttp_maybe_add_content_length_header' function to type size_t. This function is only used in the `evhttp_make_header_response' function, which correctly passes it a size_t value (evbuffer_get_length returns size_t; cf `include/event2/buffer.h'). --- http.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/http.c b/http.c index 2f6e50a..52ba574 100644 --- a/http.c +++ b/http.c @@ -519,12 +519,13 @@ evhttp_maybe_add_date_header(struct evkeyvalq *headers) * unless it already has a content-length or transfer-encoding header. */ static void evhttp_maybe_add_content_length_header(struct evkeyvalq *headers, - long content_length) /* XXX use size_t or int64, not long. */ + size_t content_length) { if (evhttp_find_header(headers, "Transfer-Encoding") == NULL && evhttp_find_header(headers, "Content-Length") == NULL) { char len[22]; - evutil_snprintf(len, sizeof(len), "%ld", content_length); + evutil_snprintf(len, sizeof(len), "%lu", + (unsigned long)content_length); evhttp_add_header(headers, "Content-Length", len); } } @@ -564,7 +565,7 @@ evhttp_make_header_response(struct evhttp_connection *evcon, */ evhttp_maybe_add_content_length_header( req->output_headers, - (long)evbuffer_get_length(req->output_buffer)); + evbuffer_get_length(req->output_buffer)); } } -- 1.7.1
From 16ad306c3bbb6d7949b1179b2e1f0c0924956df4 Mon Sep 17 00:00:00 2001 From: Mansour Moufid <mansourmou...@gmail.com> Date: Fri, 27 May 2011 18:55:37 -0400 Subject: [PATCH 5/5] Correct some `evbuffer_get_length' signedness typos in `http.c'. --- http.c | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-) diff --git a/http.c b/http.c index 52ba574..8fde01a 100644 --- a/http.c +++ b/http.c @@ -460,8 +460,8 @@ evhttp_make_header_request(struct evhttp_connection *evcon, if ((req->type == EVHTTP_REQ_POST || req->type == EVHTTP_REQ_PUT) && evhttp_find_header(req->output_headers, "Content-Length") == NULL){ char size[22]; - evutil_snprintf(size, sizeof(size), "%ld", - (long)evbuffer_get_length(req->output_buffer)); + evutil_snprintf(size, sizeof(size), "%lu", + (unsigned long)evbuffer_get_length(req->output_buffer)); evhttp_add_header(req->output_headers, "Content-Length", size); } } @@ -612,7 +612,7 @@ evhttp_make_header(struct evhttp_connection *evcon, struct evhttp_request *req) } evbuffer_add(output, "\r\n", 2); - if (evbuffer_get_length(req->output_buffer) > 0) { + if (evbuffer_get_length(req->output_buffer) != 0) { /* * For a request, we add the POST data, for a reply, this * is the regular data. @@ -841,7 +841,7 @@ evhttp_handle_chunked_read(struct evhttp_request *req, struct evbuffer *buf) { ev_ssize_t len; - while ((len = evbuffer_get_length(buf)) > 0) { + while ((len = evbuffer_get_length(buf)) != 0) { if (req->ntoread < 0) { /* Read chunk size */ ev_int64_t ntoread; @@ -975,7 +975,7 @@ evhttp_read_body(struct evhttp_connection *evcon, struct evhttp_request *req) return; } - if (evbuffer_get_length(req->input_buffer) > 0 && req->chunk_cb != NULL) { + if (evbuffer_get_length(req->input_buffer) != 0 && req->chunk_cb != NULL) { req->flags |= EVHTTP_REQ_DEFER_FREE; (*req->chunk_cb)(req, req->cb_arg); req->flags &= ~EVHTTP_REQ_DEFER_FREE; @@ -1042,9 +1042,9 @@ evhttp_read_cb(struct bufferevent *bufev, void *arg) input = bufferevent_get_input(evcon->bufev); total_len = evbuffer_get_length(input); - event_debug(("%s: read %d bytes in EVCON_IDLE state," + event_debug(("%s: read %lu bytes in EVCON_IDLE state," " resetting connection", - __func__, (int)total_len)); + __func__, (unsigned long)total_len)); #endif evhttp_connection_reset(evcon); @@ -1926,9 +1926,9 @@ evhttp_get_body_length(struct evhttp_request *req) req->ntoread = ntoread; } - event_debug(("%s: bytes to read: %ld (in buffer %ld)\n", + event_debug(("%s: bytes to read: %ld (in buffer %lu)\n", __func__, (long)req->ntoread, - evbuffer_get_length(bufferevent_get_input(req->evcon->bufev)))); + (unsigned long)evbuffer_get_length(bufferevent_get_input(req->evcon->bufev)))); return (0); } -- 1.7.1