aboutsummaryrefslogtreecommitdiff
path: root/src/or/buffers.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-02-27 11:25:34 -0500
committerNick Mathewson <nickm@torproject.org>2017-02-27 11:25:34 -0500
commitc51919b0da2afe73780508e5593ebf9052e177cc (patch)
tree2dc3c47bf9beb1af0d77b9d195538a6fec9fc732 /src/or/buffers.c
parent6747c62386964d961c3e98768e4dc9c51f8529de (diff)
parent074f24846321b8d08a8f67c37d72018842274c4e (diff)
downloadtor-c51919b0da2afe73780508e5593ebf9052e177cc.tar.gz
tor-c51919b0da2afe73780508e5593ebf9052e177cc.zip
Merge branch 'bug21369_check_029_squashed' into maint-0.3.0
Diffstat (limited to 'src/or/buffers.c')
-rw-r--r--src/or/buffers.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c
index 6111820701..603da1bb6e 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -610,6 +610,11 @@ read_to_buf(tor_socket_t s, size_t at_most, buf_t *buf, int *reached_eof,
tor_assert(reached_eof);
tor_assert(SOCKET_OK(s));
+ if (BUG(buf->datalen >= INT_MAX))
+ return -1;
+ if (BUG(buf->datalen >= INT_MAX - at_most))
+ return -1;
+
while (at_most > total_read) {
size_t readlen = at_most - total_read;
chunk_t *chunk;
@@ -667,6 +672,11 @@ read_to_buf_tls(tor_tls_t *tls, size_t at_most, buf_t *buf)
check();
+ if (BUG(buf->datalen >= INT_MAX))
+ return -1;
+ if (BUG(buf->datalen >= INT_MAX - at_most))
+ return -1;
+
while (at_most > total_read) {
size_t readlen = at_most - total_read;
chunk_t *chunk;
@@ -861,6 +871,11 @@ write_to_buf(const char *string, size_t string_len, buf_t *buf)
return (int)buf->datalen;
check();
+ if (BUG(buf->datalen >= INT_MAX))
+ return -1;
+ if (BUG(buf->datalen >= INT_MAX - string_len))
+ return -1;
+
while (string_len) {
size_t copy;
if (!buf->tail || !CHUNK_REMAINING_CAPACITY(buf->tail))
@@ -1010,6 +1025,12 @@ move_buf_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen)
/* We can do way better here, but this doesn't turn up in any profiles. */
char b[4096];
size_t cp, len;
+
+ if (BUG(buf_out->datalen >= INT_MAX))
+ return -1;
+ if (BUG(buf_out->datalen >= INT_MAX - *buf_flushlen))
+ return -1;
+
len = *buf_flushlen;
if (len > buf_in->datalen)
len = buf_in->datalen;