]> granicus.if.org Git - libevent/commitdiff
Fix wrong sie calculation of iovec buffers when exact=1
authorniks <niksniksniks@sourceforge.net>
Fri, 16 Jul 2010 13:11:09 +0000 (09:11 -0400)
committerNick Mathewson <nickm@torproject.org>
Fri, 16 Jul 2010 13:11:09 +0000 (09:11 -0400)
The old code had a bug where the 'exact' flag to 1 in
_evbuffer_read_setup_vecs would never actually make the iov_len field
of the last iovec get truncated.  This patch fixes that.

buffer.c

index 7b0262f3c1fdaf563d2e88bd4582216621bb2963..2efd0125776c3e506258092c03b9a2dc1278a6b3 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -1844,8 +1844,8 @@ _evbuffer_read_setup_vecs(struct evbuffer *buf, ev_ssize_t howmuch,
        chain = *firstchainp;
        for (i = 0; i < n_vecs_avail && so_far < howmuch; ++i) {
                size_t avail = CHAIN_SPACE_LEN(chain);
-               if (avail > howmuch && exact)
-                       avail = howmuch;
+               if (avail > (howmuch - so_far) && exact)
+                       avail = howmuch - so_far;
                vecs[i].iov_base = CHAIN_SPACE_PTR(chain);
                vecs[i].iov_len = avail;
                so_far += avail;