Skip to content

Commit

Permalink
Merge pull request #409 from nmlsg/main
Browse files Browse the repository at this point in the history
I/O problems in fuzzers
  • Loading branch information
0-wiz-0 committed Sep 22, 2023
2 parents ab892c1 + 45a6fe9 commit 5c10c39
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions regress/fuzzers/zip_read_file_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions regress/fuzzers/zip_write_encrypt_aes256_file_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions regress/fuzzers/zip_write_encrypt_pkware_file_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 5c10c39

Please sign in to comment.