From ed058fabcd20c18ea388e5f55e8260c6f79df0b1 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 8 Nov 2015 21:10:27 +0100 Subject: [PATCH] Handle getSize errors in BlockFileIO::write getSize can return -1 if the file was deleted. Just return an error to the user instead of crashing in a segmentation fault. --- encfs/BlockFileIO.cpp | 2 ++ encfs/RawFileIO.cpp | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/encfs/BlockFileIO.cpp b/encfs/BlockFileIO.cpp index ba9d060..73da4dd 100644 --- a/encfs/BlockFileIO.cpp +++ b/encfs/BlockFileIO.cpp @@ -178,6 +178,8 @@ bool BlockFileIO::write(const IORequest &req) { rAssert(_blockSize != 0); off_t fileSize = getSize(); + if (fileSize < 0) + return false; // where write request begins off_t blockNum = req.offset / _blockSize; diff --git a/encfs/RawFileIO.cpp b/encfs/RawFileIO.cpp index 339a3f9..7395d46 100644 --- a/encfs/RawFileIO.cpp +++ b/encfs/RawFileIO.cpp @@ -178,8 +178,10 @@ off_t RawFileIO::getSize() const { const_cast(this)->fileSize = stbuf.st_size; const_cast(this)->knownSize = true; return fileSize; - } else + } else { + rError("getSize on %s failed: %s", name.c_str(), strerror(errno)); return -1; + } } else { return fileSize; }