mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-14 20:30:04 +01:00
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:
12
lib/utils.c
12
lib/utils.c
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user