commit f46b9320ae32f00aa97a397b33eaa7abdcb47fe3 Author: cypherpunks cypherpunks@torproject.org Date: Thu Mar 12 16:02:00 2020 +0000
buf: add BUF_MAX_LEN --- src/core/mainloop/connection.c | 4 ++-- src/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 index 708fb13cd..f692da650 100644 --- 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 index fadd4174c..d8a77feb7 100644 --- 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);