aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorteor <teor@torproject.org>2019-08-10 07:21:31 +1000
committerteor <teor@torproject.org>2019-08-10 07:21:31 +1000
commite0f9a8222b53772a6879ecddb41738a223e3b888 (patch)
treee28cda3d2df1597a8729125c40e1e60d147ae8f9
parentc35aded00a19f26f3124584e7d0f561cf579efec (diff)
parent37bd7fa50d0901a87084b71299cc8c8786cd1cd8 (diff)
downloadtor-e0f9a8222b53772a6879ecddb41738a223e3b888.tar.gz
tor-e0f9a8222b53772a6879ecddb41738a223e3b888.zip
Merge remote-tracking branch 'tor-github/pr/1229' into maint-0.2.9
-rw-r--r--changes/bug300415
-rw-r--r--src/or/buffers.c4
-rw-r--r--src/or/connection.c4
3 files changed, 12 insertions, 1 deletions
diff --git a/changes/bug30041 b/changes/bug30041
new file mode 100644
index 0000000000..801c8f67ac
--- /dev/null
+++ b/changes/bug30041
@@ -0,0 +1,5 @@
+ o Minor bugfixes (hardening):
+ - Verify in more places that we are not about to create a buffer
+ with more than INT_MAX bytes, to avoid possible OOB access in the event
+ of bugs. Fixes bug 30041; bugfix on 0.2.0.16. Found and fixed by
+ Tobias Stoeckmann.
diff --git a/src/or/buffers.c b/src/or/buffers.c
index 89382d1d8e..b36e4ab509 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -1034,6 +1034,7 @@ buf_find_pos_of_char(char ch, buf_pos_t *out)
static inline int
buf_pos_inc(buf_pos_t *pos)
{
+ tor_assert(pos->pos < INT_MAX - 1);
++pos->pos;
if (pos->pos == (off_t)pos->chunk->datalen) {
if (!pos->chunk->next)
@@ -1925,6 +1926,7 @@ buf_find_offset_of_char(buf_t *buf, char ch)
{
chunk_t *chunk;
off_t offset = 0;
+ tor_assert(buf->datalen < INT_MAX);
for (chunk = buf->head; chunk; chunk = chunk->next) {
char *cp = memchr(chunk->data, ch, chunk->datalen);
if (cp)
@@ -2044,6 +2046,7 @@ assert_buf_ok(buf_t *buf)
for (ch = buf->head; ch; ch = ch->next) {
total += ch->datalen;
tor_assert(ch->datalen <= ch->memlen);
+ tor_assert(ch->datalen < INT_MAX);
tor_assert(ch->data >= &ch->mem[0]);
tor_assert(ch->data <= &ch->mem[0]+ch->memlen);
if (ch->data == &ch->mem[0]+ch->memlen) {
@@ -2060,4 +2063,3 @@ assert_buf_ok(buf_t *buf)
tor_assert(buf->datalen == total);
}
}
-
diff --git a/src/or/connection.c b/src/or/connection.c
index 791fd95c27..4f636eeb8c 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -3581,6 +3581,10 @@ connection_read_to_buf(connection_t *conn, ssize_t *max_to_read,
if (conn->linked_conn) {
result = move_buf_to_buf(conn->inbuf, conn->linked_conn->outbuf,
&conn->linked_conn->outbuf_flushlen);
+ if (BUG(result<0)) {
+ log_warn(LD_BUG, "reading from linked connection buffer failed.");
+ return -1;
+ }
} else {
result = 0;
}