mirror of
https://github.com/vgough/encfs.git
synced 2024-11-21 23:43:26 +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,15 +98,23 @@ 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);
|
memcpy(_cache.data, req.data, req.dataLen);
|
||||||
_cache.offset = req.offset;
|
IORequest tmp;
|
||||||
_cache.dataLen = req.dataLen;
|
tmp.offset = req.offset;
|
||||||
ssize_t res = writeOneBlock(req);
|
tmp.data = _cache.data;
|
||||||
|
tmp.dataLen = req.dataLen;
|
||||||
|
ssize_t res = writeOneBlock(tmp);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
clearCache(_cache, _blockSize);
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user