From 48fb45887f55a87b54fc6b16cf51e9565103a136 Mon Sep 17 00:00:00 2001 From: sudden6 Date: Thu, 24 Mar 2022 20:26:57 +0100 Subject: [PATCH] try to save the fuzzed save file again This should test some additional code paths. --- testing/fuzzing/toxsave_harness.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/testing/fuzzing/toxsave_harness.cc b/testing/fuzzing/toxsave_harness.cc index 80a1ba69..7005b3f7 100644 --- a/testing/fuzzing/toxsave_harness.cc +++ b/testing/fuzzing/toxsave_harness.cc @@ -1,4 +1,6 @@ #include +#include +#include #include "../../toxcore/tox.h" @@ -17,8 +19,15 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) tox_options_set_savedata_type(tox_options, TOX_SAVEDATA_TYPE_TOX_SAVE); Tox *tox = tox_new(tox_options, nullptr); - tox_options_free(tox_options); + if (tox == nullptr) { + // Tox save was invalid, we're finished here + return 0; + } + + // verify that the file can be saved again + std::vector new_savedata(tox_get_savedata_size(tox)); + tox_get_savedata(tox, new_savedata.data()); tox_kill(tox); return 0; // Non-zero return values are reserved for future use.