Skip to content

Commit

Permalink
fuzzers: move C++ code out of C section
Browse files Browse the repository at this point in the history
  • Loading branch information
0-wiz-0 committed Sep 23, 2023
1 parent 132aee7 commit 5f72d03
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 45 deletions.
29 changes: 14 additions & 15 deletions regress/fuzzers/zip_read_file_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
#include <string>
#include <zip.h>

std::string
random_string(size_t length) {
auto randchar = []() -> char {
const char charset[] = "0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
const size_t max_index = (sizeof(charset) - 1);
return charset[rand() % max_index];
};
std::string str(length, 0);
std::generate_n(str.begin(), length, randchar);
return str;
}

#ifdef __cplusplus
extern "C" {
#if 0
Expand All @@ -11,8 +25,6 @@ extern "C" {
#endif
#endif

std::string random_string(size_t length);

/**
This fuzzing target takes input data, creates a ZIP archive from it, checks the archive's consistency,
and iterates over the entries in the archive, reading data from each entry.
Expand Down Expand Up @@ -77,19 +89,6 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
return 0;
}

std::string
random_string(size_t length) {
auto randchar = []() -> char {
const char charset[] = "0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
const size_t max_index = (sizeof(charset) - 1);
return charset[rand() % max_index];
};
std::string str(length, 0);
std::generate_n(str.begin(), length, randchar);
return str;
}
#ifdef __cplusplus
}
#endif
29 changes: 14 additions & 15 deletions regress/fuzzers/zip_write_encrypt_aes256_file_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
#include <string>
#include <zip.h>

std::string
random_string(size_t length) {
auto randchar = []() -> char {
const char charset[] = "0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
const size_t max_index = (sizeof(charset) - 1);
return charset[rand() % max_index];
};
std::string str(length, 0);
std::generate_n(str.begin(), length, randchar);
return str;
}

#ifdef __cplusplus
extern "C" {
#if 0
Expand All @@ -11,8 +25,6 @@ extern "C" {
#endif
#endif

std::string random_string(size_t length);

/**
This fuzzing target takes input data, creates a ZIP archive, load
it to a buffer, adds a file to it with AES-256 encryption and a
Expand Down Expand Up @@ -71,19 +83,6 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
return 0;
}

std::string
random_string(size_t length) {
auto randchar = []() -> char {
const char charset[] = "0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
const size_t max_index = (sizeof(charset) - 1);
return charset[rand() % max_index];
};
std::string str(length, 0);
std::generate_n(str.begin(), length, randchar);
return str;
}
#ifdef __cplusplus
}
#endif
29 changes: 14 additions & 15 deletions regress/fuzzers/zip_write_encrypt_pkware_file_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
#include <string>
#include <zip.h>

std::string
random_string(size_t length) {
auto randchar = []() -> char {
const char charset[] = "0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
const size_t max_index = (sizeof(charset) - 1);
return charset[rand() % max_index];
};
std::string str(length, 0);
std::generate_n(str.begin(), length, randchar);
return str;
}

#ifdef __cplusplus
extern "C" {
#if 0
Expand All @@ -11,8 +25,6 @@ extern "C" {
#endif
#endif

std::string random_string(size_t length);

/**
This fuzzing target takes input data, creates a ZIP archive, load
it to a buffer, adds a file to it with traditional PKWARE
Expand Down Expand Up @@ -72,19 +84,6 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
return 0;
}

std::string
random_string(size_t length) {
auto randchar = []() -> char {
const char charset[] = "0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
const size_t max_index = (sizeof(charset) - 1);
return charset[rand() % max_index];
};
std::string str(length, 0);
std::generate_n(str.begin(), length, randchar);
return str;
}
#ifdef __cplusplus
}
#endif

0 comments on commit 5f72d03

Please sign in to comment.