diff --git a/tests/fuzz/crypt2_load_fuzz.cc b/tests/fuzz/crypt2_load_fuzz.cc index d3de9a96..0ad4f827 100644 --- a/tests/fuzz/crypt2_load_fuzz.cc +++ b/tests/fuzz/crypt2_load_fuzz.cc @@ -107,9 +107,7 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { err(EXIT_FAILURE, "mkostemp() failed"); /* enlarge header */ - if (lseek(fd, FILESIZE-1, SEEK_SET) == -1 || - write(fd, "\0", 1) < 1 || - lseek(fd, 0, SEEK_SET) == -1) + if (ftruncate(fd, FILESIZE) == -1) goto out; if (write_buffer(fd, data, size) != (ssize_t)size) diff --git a/tests/fuzz/plain_json_proto_to_luks2_converter.cc b/tests/fuzz/plain_json_proto_to_luks2_converter.cc index cbf7bef0..c6de05a7 100644 --- a/tests/fuzz/plain_json_proto_to_luks2_converter.cc +++ b/tests/fuzz/plain_json_proto_to_luks2_converter.cc @@ -123,13 +123,9 @@ void LUKS2ProtoConverter::convert(const LUKS2_both_headers &headers, int fd) { if (!write_headers_only) out_size += KEYSLOTS_SIZE + DATA_SIZE; - result = lseek(fd, out_size - 1, SEEK_SET); + result = ftruncate(fd, out_size); if (result == -1) - err(EXIT_FAILURE, "lseek failed"); - - result = write(fd, "\0", 1); - if (result != 1) - err(EXIT_FAILURE, "write failed"); + err(EXIT_FAILURE, "truncate failed"); result = lseek(fd, 0, SEEK_SET); if (result == -1) diff --git a/tests/fuzz/proto_to_luks2_converter.cc b/tests/fuzz/proto_to_luks2_converter.cc index 87dc1841..3f74898c 100644 --- a/tests/fuzz/proto_to_luks2_converter.cc +++ b/tests/fuzz/proto_to_luks2_converter.cc @@ -511,13 +511,9 @@ void LUKS2ProtoConverter::convert(const LUKS2_both_headers &headers, int fd) { if (!write_headers_only) out_size += KEYSLOTS_SIZE + DATA_SIZE; - result = lseek(fd, out_size - 1, SEEK_SET); + result = ftruncate(fd, out_size); if (result == -1) - err(EXIT_FAILURE, "lseek failed"); - - result = write(fd, "\0", 1); - if (result != 1) - err(EXIT_FAILURE, "write failed"); + err(EXIT_FAILURE, "truncate failed"); result = lseek(fd, 0, SEEK_SET); if (result == -1)