fuzzing: use ftruncate() instead of seeking to end of the file

This commit is contained in:
Milan Broz
2022-10-09 12:28:16 +02:00
parent f03180d06a
commit 98f5e0538a
3 changed files with 5 additions and 15 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)