From e752070d06f3ca6a758c04ae113d7a179f825a08 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 16 Mar 2019 13:49:04 -0700 Subject: [PATCH] ircd::fs: Handle zero length buffers in the iov. --- ircd/fs.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ircd/fs.cc b/ircd/fs.cc index 9ddb515b3..9cebca8f8 100644 --- a/ircd/fs.cc +++ b/ircd/fs.cc @@ -1412,12 +1412,14 @@ ircd::fs::make_iov(const iovec_view &iov, size_t i(0), off(0); for(; i < max; off += size(bufs[i++])) - if(size(bufs[i]) > offset - off) + if(size(bufs[i]) >= offset - off) { + assert(offset >= off); off = offset - off; break; } + assert(i <= max); if(i < max) { assert(off <= size(bufs[i])); @@ -1433,6 +1435,7 @@ ircd::fs::make_iov(const iovec_view &iov, }; } + assert(i <= max); const const_iovec_view ret{iov.data(), i}; assert(bytes(ret) <= buffer::buffers::size(bufs)); return ret; @@ -1451,12 +1454,14 @@ ircd::fs::make_iov(const iovec_view &iov, size_t i(0), off(0); for(; i < max; off += size(bufs[i++])) - if(size(bufs[i]) > offset - off) + if(size(bufs[i]) >= offset - off) { + assert(offset >= off); off = offset - off; break; } + assert(i <= max); if(i < max) { assert(off <= size(bufs[i])); @@ -1472,6 +1477,7 @@ ircd::fs::make_iov(const iovec_view &iov, }; } + assert(i <= max); const const_iovec_view ret{iov.data(), i}; assert(bytes(ret) <= buffer::buffers::size(bufs)); return ret;