tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

commit f46b9320ae32f00aa97a397b33eaa7abdcb47fe3
parent d3ded1cc1c4a1bcd158c1705c4c26425ed538be9
Author: cypherpunks <cypherpunks@torproject.org>
Date:   Thu, 12 Mar 2020 16:02:00 +0000

buf: add BUF_MAX_LEN

Diffstat:
Msrc/core/mainloop/connection.c | 4++--
Msrc/lib/buf/buffers.h | 3+++
2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c @@ -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; } diff --git a/src/lib/buf/buffers.h b/src/lib/buf/buffers.h @@ -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);