]> granicus.if.org Git - libevent/commitdiff
Address issue #306 - use misalign instead of evbuffer_remove 20-issue306-fix
authorMark Ellzey <socket@gmail.com>
Thu, 24 Dec 2015 03:03:57 +0000 (19:03 -0800)
committerMark Ellzey <socket@gmail.com>
Thu, 24 Dec 2015 03:03:57 +0000 (19:03 -0800)
when evbuffer_add_file is called and mmap is used, if the offset
argument is >0, a mistake happens: add_file removes "offset" byts
from the front of the evbuffer.

So that means any data that was previously on the buffer is trimmed
off by "offset" bytes. Whoops.

A onelinter fix: don't use evbuffer_drain for the offset, instead,
just modify the misalign variable on the newly created chain.

buffer.c

index 8510955b7b9d6f7997456220f7348b4a064ba806..56ff983ee0936a9c97b94ae6252524cef4277559 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -2868,6 +2868,11 @@ evbuffer_add_file(struct evbuffer *outbuf, int fd,
                chain->buffer_len = length + offset;
                chain->off = length + offset;
 
+               /* make way for pointing to the offset in the new chain if the
+                * offset was equested
+                */
+               chain->misalign = offset;
+
                info = EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_fd, chain);
                info->fd = fd;
 
@@ -2880,9 +2885,6 @@ evbuffer_add_file(struct evbuffer *outbuf, int fd,
                        outbuf->n_add_for_cb += length;
 
                        evbuffer_chain_insert(outbuf, chain);
-
-                       /* we need to subtract whatever we don't need */
-                       evbuffer_drain(outbuf, offset);
                }
        } else
 #endif