diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2020-05-15 17:17:24 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2020-05-15 17:18:27 +0000 |
commit | 81773f55a430e75fe5c6bee355ca518f16286dd1 (patch) | |
tree | fc7ac88a76cc6a06cf5310ef2a353be92d6bb931 /tests/fuzz/load_from_binary.cpp | |
parent | Merge pull request #6510 (diff) | |
download | monero-81773f55a430e75fe5c6bee355ca518f16286dd1.tar.xz |
fuzz_tests: refactor and add OSS-Fuzz compatibility
Diffstat (limited to 'tests/fuzz/load_from_binary.cpp')
-rw-r--r-- | tests/fuzz/load_from_binary.cpp | 48 |
1 files changed, 6 insertions, 42 deletions
diff --git a/tests/fuzz/load_from_binary.cpp b/tests/fuzz/load_from_binary.cpp index 85b7361e5..b185df522 100644 --- a/tests/fuzz/load_from_binary.cpp +++ b/tests/fuzz/load_from_binary.cpp @@ -33,46 +33,10 @@ #include "storages/portable_storage_base.h" #include "fuzzer.h" -class PortableStorageFuzzer: public Fuzzer -{ -public: - PortableStorageFuzzer() {} - virtual int init(); - virtual int run(const std::string &filename); -}; - -int PortableStorageFuzzer::init() -{ - return 0; -} - -int PortableStorageFuzzer::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; - } - try - { - epee::serialization::portable_storage ps; - ps.load_from_binary(s); - } - catch (const std::exception &e) - { - std::cerr << "Failed to load from binary: " << e.what() << std::endl; - return 1; - } - return 0; -} - -int main(int argc, const char **argv) -{ - TRY_ENTRY(); - PortableStorageFuzzer fuzzer; - return run_fuzzer(argc, argv, fuzzer); - CATCH_ENTRY_L0("main", 1); -} +BEGIN_INIT_SIMPLE_FUZZER() +END_INIT_SIMPLE_FUZZER() +BEGIN_SIMPLE_FUZZER() + epee::serialization::portable_storage ps; + ps.load_from_binary(std::string((const char*)buf, len)); +END_SIMPLE_FUZZER() |