From 003ada6d2915ac6b6025e28f900c7dabe9994325 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 27 Apr 2022 02:06:42 +0100 Subject: Handle case where zero size passes null to pread --- netfs/daemon/daemonFile.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/netfs/daemon/daemonFile.cpp b/netfs/daemon/daemonFile.cpp index fb146a4..cf34b7d 100644 --- a/netfs/daemon/daemonFile.cpp +++ b/netfs/daemon/daemonFile.cpp @@ -44,14 +44,16 @@ NetFS::Buffer FileServer::read(Ice::Long offset, Ice::Long size, const Ice::Current &) { NetFS::Buffer buf; - buf.resize(safe {size}); - errno = 0; - auto r = pread(fd, &buf[0], safe {size}, offset); - if (r == -1) { - throw NetFS::SystemError(errno); - } - else if (std::cmp_not_equal(r, size)) { - buf.resize(safe {r}); + if (size) { + buf.resize(safe {size}); + errno = 0; + auto r = pread(fd, buf.data(), safe {size}, offset); + if (r == -1) { + throw NetFS::SystemError(errno); + } + else if (std::cmp_not_equal(r, size)) { + buf.resize(safe {r}); + } } return buf; } -- cgit v1.2.3