Correct a possible write crash (#494)

Originate buffer was modified by encryption, which can lead to an EncFS crash, as originate application may not like its buffer to be overwritten
This commit is contained in:
Ben RUBSON 2018-03-26 08:09:01 +02:00 committed by GitHub
parent b80d30755c
commit 9197385331
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -98,15 +98,23 @@ ssize_t BlockFileIO::cacheReadOneBlock(const IORequest &req) const {
}
ssize_t BlockFileIO::cacheWriteOneBlock(const IORequest &req) {
// cache results of write (before pass-thru, because it may be modified
// in-place)
// Let's point request buffer to our own buffer, as it may be modified by
// encryption : originating process may not like to have its buffer modified
memcpy(_cache.data, req.data, req.dataLen);
_cache.offset = req.offset;
_cache.dataLen = req.dataLen;
ssize_t res = writeOneBlock(req);
IORequest tmp;
tmp.offset = req.offset;
tmp.data = _cache.data;
tmp.dataLen = req.dataLen;
ssize_t res = writeOneBlock(tmp);
if (res < 0) {
clearCache(_cache, _blockSize);
}
else {
// And now we can cache the write buffer from the request
memcpy(_cache.data, req.data, req.dataLen);
_cache.offset = req.offset;
_cache.dataLen = req.dataLen;
}
return res;
}