From afca576a052fb8c83e771435169615fce5c56686 Mon Sep 17 00:00:00 2001 From: Mark Ellzey Date: Wed, 23 Dec 2015 19:03:57 -0800 Subject: [PATCH] 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. --- buffer.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 -- 2.40.0