summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-04-27 02:06:42 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2022-04-27 02:06:42 +0100
commit003ada6d2915ac6b6025e28f900c7dabe9994325 (patch)
treec86983a03ef450c46aa7a7b635fc0e42649073d9
parentPrefer std::copy over memcpy, handles case of null data ptr when empty (diff)
downloadnetfs-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.cpp18
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;
}