mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-12 03:10:08 +01:00
fuzzing: use ftruncate() instead of seeking to end of the file
This commit is contained in:
@@ -107,9 +107,7 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|||||||
err(EXIT_FAILURE, "mkostemp() failed");
|
err(EXIT_FAILURE, "mkostemp() failed");
|
||||||
|
|
||||||
/* enlarge header */
|
/* enlarge header */
|
||||||
if (lseek(fd, FILESIZE-1, SEEK_SET) == -1 ||
|
if (ftruncate(fd, FILESIZE) == -1)
|
||||||
write(fd, "\0", 1) < 1 ||
|
|
||||||
lseek(fd, 0, SEEK_SET) == -1)
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (write_buffer(fd, data, size) != (ssize_t)size)
|
if (write_buffer(fd, data, size) != (ssize_t)size)
|
||||||
|
|||||||
@@ -123,13 +123,9 @@ void LUKS2ProtoConverter::convert(const LUKS2_both_headers &headers, int fd) {
|
|||||||
if (!write_headers_only)
|
if (!write_headers_only)
|
||||||
out_size += KEYSLOTS_SIZE + DATA_SIZE;
|
out_size += KEYSLOTS_SIZE + DATA_SIZE;
|
||||||
|
|
||||||
result = lseek(fd, out_size - 1, SEEK_SET);
|
result = ftruncate(fd, out_size);
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
err(EXIT_FAILURE, "lseek failed");
|
err(EXIT_FAILURE, "truncate failed");
|
||||||
|
|
||||||
result = write(fd, "\0", 1);
|
|
||||||
if (result != 1)
|
|
||||||
err(EXIT_FAILURE, "write failed");
|
|
||||||
|
|
||||||
result = lseek(fd, 0, SEEK_SET);
|
result = lseek(fd, 0, SEEK_SET);
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
|
|||||||
@@ -511,13 +511,9 @@ void LUKS2ProtoConverter::convert(const LUKS2_both_headers &headers, int fd) {
|
|||||||
if (!write_headers_only)
|
if (!write_headers_only)
|
||||||
out_size += KEYSLOTS_SIZE + DATA_SIZE;
|
out_size += KEYSLOTS_SIZE + DATA_SIZE;
|
||||||
|
|
||||||
result = lseek(fd, out_size - 1, SEEK_SET);
|
result = ftruncate(fd, out_size);
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
err(EXIT_FAILURE, "lseek failed");
|
err(EXIT_FAILURE, "truncate failed");
|
||||||
|
|
||||||
result = write(fd, "\0", 1);
|
|
||||||
if (result != 1)
|
|
||||||
err(EXIT_FAILURE, "write failed");
|
|
||||||
|
|
||||||
result = lseek(fd, 0, SEEK_SET);
|
result = lseek(fd, 0, SEEK_SET);
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
|
|||||||
Reference in New Issue
Block a user