buf: add BUF_MAX_LEN

This commit is contained in:
cypherpunks 2020-03-12 16:02:00 +00:00
parent d3ded1cc1c
commit f46b9320ae
2 changed files with 5 additions and 2 deletions

View File

@ -3804,8 +3804,8 @@ connection_buf_read_from_socket(connection_t *conn, ssize_t *max_to_read,
at_most = connection_bucket_read_limit(conn, approx_time());
}
/* Do not allow inbuf to grow past INT_MAX - 1. */
const ssize_t maximum = INT_MAX - 1 - buf_datalen(conn->inbuf);
/* Do not allow inbuf to grow past BUF_MAX_LEN. */
const ssize_t maximum = BUF_MAX_LEN - buf_datalen(conn->inbuf);
if (at_most > maximum) {
at_most = maximum;
}

View File

@ -29,6 +29,9 @@ void buf_free_(buf_t *buf);
void buf_clear(buf_t *buf);
buf_t *buf_copy(const buf_t *buf);
/** Maximum bytes in a buffer, inclusive. */
#define BUF_MAX_LEN (INT_MAX - 1)
MOCK_DECL(size_t, buf_datalen, (const buf_t *buf));
size_t buf_allocation(const buf_t *buf);
size_t buf_slack(const buf_t *buf);