diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-04-27 02:06:42 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-04-27 02:06:42 +0100 |
commit | 003ada6d2915ac6b6025e28f900c7dabe9994325 (patch) | |
tree | c86983a03ef450c46aa7a7b635fc0e42649073d9 | |
parent | Prefer std::copy over memcpy, handles case of null data ptr when empty (diff) | |
download | netfs-003ada6d2915ac6b6025e28f900c7dabe9994325.tar.bz2 netfs-003ada6d2915ac6b6025e28f900c7dabe9994325.tar.xz netfs-003ada6d2915ac6b6025e28f900c7dabe9994325.zip |
Handle case where zero size passes null to pread
-rw-r--r-- | netfs/daemon/daemonFile.cpp | 18 |
1 files 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; } |