diff --git a/regress/fuzzers/zip_read_file_fuzzer.cc b/regress/fuzzers/zip_read_file_fuzzer.cc index 730b12494..3b5a02097 100644 --- a/regress/fuzzers/zip_read_file_fuzzer.cc +++ b/regress/fuzzers/zip_read_file_fuzzer.cc @@ -37,6 +37,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { za = zip_open(name.c_str(), 0, NULL); if (za == NULL) { + std::remove(name.c_str()); std::cerr << "Error opening archive." << std::endl; return 1; } @@ -45,6 +46,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { for (i = 0; i < n; i++) { f = zip_fopen_index(za, i, 0); if (f == NULL) { + std::remove(name.c_str()); std::cerr << "Unable to open file." << std::endl; zip_close(za); return 1; @@ -54,22 +56,24 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { ; } if (zip_fclose(f) < 0) { + std::remove(name.c_str()); std::cerr << "Error closing file." << std::endl; zip_close(za); return 1; } } if (zip_close(za) < 0) { + std::remove(name.c_str()); std::cerr << "Error closing archive." << std::endl; return 1; } - std::remove(name.c_str()); } else { + std::remove(name.c_str()); std::cerr << "Unable to open the file." << std::endl; return 1; } - + std::remove(name.c_str()); return 0; } diff --git a/regress/fuzzers/zip_write_encrypt_aes256_file_fuzzer.cc b/regress/fuzzers/zip_write_encrypt_aes256_file_fuzzer.cc index 598dff82f..26df529ae 100644 --- a/regress/fuzzers/zip_write_encrypt_aes256_file_fuzzer.cc +++ b/regress/fuzzers/zip_write_encrypt_aes256_file_fuzzer.cc @@ -39,25 +39,30 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { struct zip *archive = zip_open(path.c_str(), ZIP_CREATE, &error); if (error) { + std::remove(path.c_str()); return -1; } struct zip_source *source = zip_source_buffer(archive, data, size, 0); if (source == NULL) { + std::remove(path.c_str()); printf("failed to create source buffer. %s\n", zip_strerror(archive)); return -1; } int index = (int)zip_file_add(archive, file.c_str(), source, ZIP_FL_OVERWRITE); if (index < 0) { + std::remove(path.c_str()); printf("failed to add file to archive: %s\n", zip_strerror(archive)); return -1; } if (zip_file_set_encryption(archive, index, ZIP_EM_AES_256, password.c_str()) < 0) { + std::remove(path.c_str()); printf("failed to set file encryption: %s\n", zip_strerror(archive)); return -1; } if (zip_close(archive) < 0) { + std::remove(path.c_str()); printf("error closing archive: %s\n", zip_strerror(archive)); return -1; } diff --git a/regress/fuzzers/zip_write_encrypt_pkware_file_fuzzer.cc b/regress/fuzzers/zip_write_encrypt_pkware_file_fuzzer.cc index 8dd697a8c..06773fd34 100644 --- a/regress/fuzzers/zip_write_encrypt_pkware_file_fuzzer.cc +++ b/regress/fuzzers/zip_write_encrypt_pkware_file_fuzzer.cc @@ -40,25 +40,30 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { struct zip *archive = zip_open(path.c_str(), ZIP_CREATE, &error); if (error) { + std::remove(path.c_str()); return -1; } struct zip_source *source = zip_source_buffer(archive, data, size, 0); if (source == NULL) { + std::remove(path.c_str()); printf("failed to create source buffer. %s\n", zip_strerror(archive)); return -1; } int index = (int)zip_file_add(archive, file.c_str(), source, ZIP_FL_OVERWRITE); if (index < 0) { + std::remove(path.c_str()); printf("failed to add file to archive: %s\n", zip_strerror(archive)); return -1; } if (zip_file_set_encryption(archive, index, ZIP_EM_TRAD_PKWARE, password.c_str()) < 0) { + std::remove(path.c_str()); printf("failed to set file encryption: %s\n", zip_strerror(archive)); return -1; } if (zip_close(archive) < 0) { + std::remove(path.c_str()); printf("error closing archive: %s\n", zip_strerror(archive)); return -1; }