mirror of
https://github.com/vgough/encfs.git
synced 2024-11-22 07:53:31 +01:00
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:
parent
b80d30755c
commit
9197385331
@ -98,14 +98,22 @@ ssize_t BlockFileIO::cacheReadOneBlock(const IORequest &req) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ssize_t BlockFileIO::cacheWriteOneBlock(const IORequest &req) {
|
ssize_t BlockFileIO::cacheWriteOneBlock(const IORequest &req) {
|
||||||
// cache results of write (before pass-thru, because it may be modified
|
// Let's point request buffer to our own buffer, as it may be modified by
|
||||||
// in-place)
|
// encryption : originating process may not like to have its buffer modified
|
||||||
|
memcpy(_cache.data, req.data, req.dataLen);
|
||||||
|
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);
|
memcpy(_cache.data, req.data, req.dataLen);
|
||||||
_cache.offset = req.offset;
|
_cache.offset = req.offset;
|
||||||
_cache.dataLen = req.dataLen;
|
_cache.dataLen = req.dataLen;
|
||||||
ssize_t res = writeOneBlock(req);
|
|
||||||
if (res < 0) {
|
|
||||||
clearCache(_cache, _blockSize);
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user