fuzz_tests: refactor and add OSS-Fuzz compatibility

This commit is contained in:
moneromooo-monero 2020-05-15 17:17:24 +00:00
parent 77a008f714
commit 81773f55a4
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
16 changed files with 232 additions and 538 deletions

View file

@ -33,36 +33,10 @@
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "fuzzer.h"
class BlockFuzzer: public Fuzzer
{
public:
virtual int run(const std::string &filename);
BEGIN_INIT_SIMPLE_FUZZER()
END_INIT_SIMPLE_FUZZER()
private:
};
int BlockFuzzer::run(const std::string &filename)
{
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;
}
BEGIN_SIMPLE_FUZZER()
cryptonote::block b = AUTO_VAL_INIT(b);
if(!parse_and_validate_block_from_blob(s, b))
{
std::cout << "Error: failed to parse block from file " << filename << std::endl;
return 1;
}
return 0;
}
int main(int argc, const char **argv)
{
TRY_ENTRY();
BlockFuzzer fuzzer;
return run_fuzzer(argc, argv, fuzzer);
CATCH_ENTRY_L0("main", 1);
}
parse_and_validate_block_from_blob(std::string((const char*)buf, len), b);
END_SIMPLE_FUZZER()