From: Mark Ellzey Date: Thu, 24 Dec 2015 03:03:57 +0000 (-0800) Subject: Address issue #306 - use misalign instead of evbuffer_remove X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=refs%2Fheads%2F20-issue306-fix;p=libevent Address issue #306 - use misalign instead of evbuffer_remove 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. --- diff --git a/buffer.c b/buffer.c index 8510955b..56ff983e 100644 --- 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