Fix access to unaligned hidden TrueCrypt header.

On native 4k-sector device the old hidden header is not aligned
with hw sector size and derect-io access with SEEK_END fails.

Let's extend blockwise functions to support a negative offset
and use the same logic as normal unaligned writes.

Fixes problem mentioned in
https://gitlab.com/cryptsetup/cryptsetup/merge_requests/18
This commit is contained in:
Milan Broz
2017-03-27 12:04:31 +02:00
parent 7c25327396
commit e91b90b8c9
2 changed files with 22 additions and 11 deletions

View File

@@ -235,6 +235,12 @@ ssize_t write_lseek_blockwise(int fd, int bsize, void *buf, size_t count, off_t
if (fd == -1 || !buf || bsize <= 0)
return -1;
if (offset < 0)
offset = lseek(fd, offset, SEEK_END);
if (offset < 0)
return -1;
frontHang = offset % bsize;
if (lseek(fd, offset - frontHang, SEEK_SET) < 0)
@@ -287,6 +293,12 @@ ssize_t read_lseek_blockwise(int fd, int bsize, void *buf, size_t count, off_t o
if (fd == -1 || !buf || bsize <= 0)
return -1;
if (offset < 0)
offset = lseek(fd, offset, SEEK_END);
if (offset < 0)
return -1;
frontHang = offset % bsize;
if (lseek(fd, offset - frontHang, SEEK_SET) < 0)