mirror of
https://github.com/monero-project/monero.git
synced 2025-08-06 08:34:20 -04:00
fuzz_tests: refactor and add OSS-Fuzz compatibility
This commit is contained in:
parent
77a008f714
commit
81773f55a4
16 changed files with 232 additions and 538 deletions
|
@ -27,6 +27,52 @@
|
|||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <string>
|
||||
#include "file_io_utils.h"
|
||||
|
||||
#ifdef OSSFUZZ
|
||||
|
||||
#define BEGIN_INIT_SIMPLE_FUZZER() \
|
||||
static int init() \
|
||||
{ \
|
||||
try \
|
||||
{
|
||||
|
||||
#define END_INIT_SIMPLE_FUZZER() \
|
||||
} \
|
||||
catch (const std::exception &e) \
|
||||
{ \
|
||||
fprintf(stderr, "Exception: %s\n", e.what()); \
|
||||
return 1; \
|
||||
} \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
#define BEGIN_SIMPLE_FUZZER() \
|
||||
extern "C" { \
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) \
|
||||
{ \
|
||||
try \
|
||||
{ \
|
||||
static bool first = true; \
|
||||
if (first) \
|
||||
{ \
|
||||
if (!init()) \
|
||||
return 1; \
|
||||
first = false; \
|
||||
} \
|
||||
|
||||
#define END_SIMPLE_FUZZER() \
|
||||
} \
|
||||
catch (const std::exception &e) \
|
||||
{ \
|
||||
fprintf(stderr, "Exception: %s\n", e.what()); \
|
||||
return 1; \
|
||||
} \
|
||||
return 0; \
|
||||
} \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
class Fuzzer
|
||||
{
|
||||
|
@ -36,3 +82,57 @@ public:
|
|||
};
|
||||
|
||||
int run_fuzzer(int argc, const char **argv, Fuzzer &fuzzer);
|
||||
|
||||
#define BEGIN_INIT_SIMPLE_FUZZER() \
|
||||
class SimpleFuzzer: public Fuzzer \
|
||||
{ \
|
||||
virtual int init() \
|
||||
{ \
|
||||
try \
|
||||
{
|
||||
|
||||
#define END_INIT_SIMPLE_FUZZER() \
|
||||
} \
|
||||
catch (const std::exception &e) \
|
||||
{ \
|
||||
fprintf(stderr, "Exception: %s\n", e.what()); \
|
||||
return 1; \
|
||||
} \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
#define BEGIN_SIMPLE_FUZZER() \
|
||||
virtual int run(const std::string &filename) \
|
||||
{ \
|
||||
try \
|
||||
{ \
|
||||
std::string s; \
|
||||
if (!epee::file_io_utils::load_file_to_string(filename, s)) \
|
||||
{ \
|
||||
std::cout << "Error: failed to load file " << filename << std::endl; \
|
||||
return 1; \
|
||||
} \
|
||||
const uint8_t *buf = (const uint8_t*)s.data(); \
|
||||
const size_t len = s.size(); \
|
||||
{
|
||||
|
||||
#define END_SIMPLE_FUZZER() \
|
||||
} \
|
||||
} \
|
||||
catch (const std::exception &e) \
|
||||
{ \
|
||||
fprintf(stderr, "Exception: %s\n", e.what()); \
|
||||
return 1; \
|
||||
} \
|
||||
return 0; \
|
||||
} \
|
||||
}; \
|
||||
int main(int argc, const char **argv) \
|
||||
{ \
|
||||
TRY_ENTRY(); \
|
||||
SimpleFuzzer fuzzer; \
|
||||
return run_fuzzer(argc, argv, fuzzer); \
|
||||
CATCH_ENTRY_L0("main", 1); \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue