From 36f3505af03344b1ce38633d3e85f9d4675206d5 Mon Sep 17 00:00:00 2001 From: benrubson Date: Thu, 16 Mar 2017 15:48:19 +0100 Subject: [PATCH] Make readOneBlock return -EBADMSG when decode fails instead of throwing an exception, as with writeOneBlock --- encfs/BlockFileIO.cpp | 4 ++++ encfs/CipherFileIO.cpp | 2 +- encfs/MACFileIO.cpp | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/encfs/BlockFileIO.cpp b/encfs/BlockFileIO.cpp index 73333bc..d440dac 100644 --- a/encfs/BlockFileIO.cpp +++ b/encfs/BlockFileIO.cpp @@ -147,6 +147,10 @@ ssize_t BlockFileIO::read(const IORequest &req) const { } ssize_t readSize = cacheReadOneBlock(blockReq); + if (readSize < 0) { + result = readSize; + break; + } if (readSize <= partialOffset) break; // didn't get enough bytes int cpySize = min((size_t)(readSize - partialOffset), size); diff --git a/encfs/CipherFileIO.cpp b/encfs/CipherFileIO.cpp index ef099b7..4d1b510 100644 --- a/encfs/CipherFileIO.cpp +++ b/encfs/CipherFileIO.cpp @@ -337,7 +337,7 @@ ssize_t CipherFileIO::readOneBlock(const IORequest &req) const { if (!ok) { VLOG(1) << "decodeBlock failed for block " << blockNum << ", size " << readSize; - readSize = -1; + readSize = -EBADMSG; } } else { VLOG(1) << "readSize zero for offset " << req.offset; diff --git a/encfs/MACFileIO.cpp b/encfs/MACFileIO.cpp index b09ed40..3b503cb 100644 --- a/encfs/MACFileIO.cpp +++ b/encfs/MACFileIO.cpp @@ -190,7 +190,7 @@ ssize_t MACFileIO::readOneBlock(const IORequest &req) const { RLOG(WARNING) << "MAC comparison failure in block " << blockNum; if (!warnOnly) { MemoryPool::release(mb); - throw Error(_("MAC comparison failure, refusing to read")); + return -EBADMSG; } } }