/* evbuffer_get_length returns size_t, but len variable is ssize_t,
* check for overflow conditions */
- if (buflen > SSIZE_MAX) {
+ if (buflen > EV_SSIZE_MAX) {
return DATA_CORRUPTED;
}
}
/* ntoread is signed int64, body_size is unsigned size_t, check for under/overflow conditions */
- if ((ntoread + req->body_size) < ntoread) {
- return DATA_CORRUPTED;
+ if (ntoread > EV_SIZE_MAX - req->body_size) {
+ return DATA_CORRUPTED;
}
if (req->body_size + (size_t)ntoread > req->evcon->max_body_size) {
event_debug(("Request body is too long"));
return (DATA_TOO_LONG);
}
+
req->body_size += (size_t)ntoread;
req->ntoread = ntoread;
if (req->ntoread == 0) {
/* req->ntoread is signed int64, len is ssize_t, based on arch,
* ssize_t could only be 32b, check for these conditions */
- if (req->ntoread > SSIZE_MAX) {
+ if (req->ntoread > EV_SSIZE_MAX) {
return DATA_CORRUPTED;
}
}
} else if (req->ntoread < 0) {
/* Read until connection close. */
- /* check for overflow condition */
- if ((req->body_size + evbuffer_get_length(buf)) < req->body_size) {
+ if ((size_t)(req->body_size + evbuffer_get_length(buf)) < req->body_size) {
evhttp_connection_fail(evcon, EVCON_HTTP_INVALID_HEADER);
return;
}
send their message body. */
if (req->ntoread > 0) {
/* ntoread is ev_int64_t, max_body_size is ev_uint64_t */
- if ((req->evcon->max_body_size <= INT64_MAX) && (ev_uint64_t)req->ntoread > req->evcon->max_body_size) {
+ if ((req->evcon->max_body_size <= EV_INT64_MAX) && (ev_uint64_t)req->ntoread > req->evcon->max_body_size) {
evhttp_send_error(req, HTTP_ENTITYTOOLARGE, NULL);
return;
}