From 37f2f548bf7fd6a6857a127df59ea751ab4721f7 Mon Sep 17 00:00:00 2001 From: Roger Dingledine Date: Sun, 2 Mar 2008 07:11:09 +0000 Subject: [PATCH] We were sometimes miscounting the number of bytes read from the network, causing our rate limiting to not be followed exactly. Bugfix on 0.2.0.16-alpha. Reported by lodger. svn:r13799 --- ChangeLog | 7 ++++++- src/or/buffers.c | 17 +++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index b9b31e6da5..7278da5192 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,11 +1,16 @@ Changes in version 0.2.0.21-rc - 2008-0?-?? - o Bugfixes: + o Major bugfixes: - The control port should declare that it requires password auth when HashedControlSessionPassword is set too. Patch from Matt Edman; bugfix on 0.2.0.20-rc. Fixes bug 615. - Downgrade assert in connection_buckets_decrement() to a log message. This may help us solve bug 614, and in any case will make its symptoms less severe. Bugfix on 0.2.0.20-rc. + - We were sometimes miscounting the number of bytes read from the + network, causing our rate limiting to not be followed exactly. + Bugfix on 0.2.0.16-alpha. Reported by lodger. + + o Minor bugfixes: - Fix compilation with OpenSSL 0.9.8 and 0.9.8a. All other supported OpenSSL versions should have been working fine. Diagnosis and patch from lodger, Karsten Loesing and Sebastian Hahn. Fixes bug 616. diff --git a/src/or/buffers.c b/src/or/buffers.c index 7b54dd3968..99e8b0a3ab 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -635,13 +635,13 @@ read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof) check(); if (r < 0) return r; /* Error */ - else if ((size_t)r < readlen) { /* eof, block, or no more to read. */ - tor_assert(r+total_read < INT_MAX); - return (int)(r + total_read); - } + tor_assert(total_read+r < INT_MAX); total_read += r; + if ((size_t)r < readlen) { /* eof, block, or no more to read. */ + break; + } } - return r; + return (int)total_read; } /** As read_to_buf, but reads from a TLS connection, and returns a TLS @@ -689,11 +689,12 @@ read_to_buf_tls(tor_tls_t *tls, size_t at_most, buf_t *buf) check(); if (r < 0) return r; /* Error */ - else if ((size_t)r < readlen) /* eof, block, or no more to read. */ - return r; + tor_assert(total_read+r < INT_MAX); total_read += r; + if ((size_t)r < readlen) /* eof, block, or no more to read. */ + break; } - return r; + return (int)total_read; } /** Helper for flush_buf(): try to write sz bytes from chunk