2021-12-05 20:10:03 +08:00
|
|
|
#include <cassert>
|
2022-03-25 03:26:57 +08:00
|
|
|
#include <cstdint>
|
|
|
|
#include <vector>
|
2021-12-05 20:10:03 +08:00
|
|
|
|
2021-12-05 20:07:27 +08:00
|
|
|
#include "../../toxcore/tox.h"
|
2022-03-29 06:42:42 +08:00
|
|
|
#include "../../toxcore/tox_private.h"
|
2024-02-02 07:41:53 +08:00
|
|
|
#include "fuzz_support.hh"
|
2021-12-05 20:07:27 +08:00
|
|
|
|
2022-04-03 01:10:09 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
void TestSaveDataLoading(Fuzz_Data &input)
|
2022-02-19 11:24:01 +08:00
|
|
|
{
|
|
|
|
Tox_Err_Options_New error_options;
|
2021-12-05 20:07:27 +08:00
|
|
|
|
2022-02-19 11:24:01 +08:00
|
|
|
struct Tox_Options *tox_options = tox_options_new(&error_options);
|
2021-12-05 20:07:27 +08:00
|
|
|
|
2022-02-19 11:24:01 +08:00
|
|
|
assert(tox_options != nullptr);
|
|
|
|
assert(error_options == TOX_ERR_OPTIONS_NEW_OK);
|
2021-12-05 20:07:27 +08:00
|
|
|
|
2024-01-13 00:11:07 +08:00
|
|
|
const size_t savedata_size = input.size();
|
2022-04-03 01:10:09 +08:00
|
|
|
CONSUME_OR_RETURN(const uint8_t *savedata, input, savedata_size);
|
|
|
|
|
2022-04-15 02:58:45 +08:00
|
|
|
Null_System sys;
|
2022-04-03 01:10:09 +08:00
|
|
|
tox_options_set_operating_system(tox_options, sys.sys.get());
|
2022-03-29 06:42:42 +08:00
|
|
|
|
2022-02-19 11:24:01 +08:00
|
|
|
// pass test data to Tox
|
2022-04-03 01:10:09 +08:00
|
|
|
tox_options_set_savedata_data(tox_options, savedata, savedata_size);
|
2022-02-19 11:24:01 +08:00
|
|
|
tox_options_set_savedata_type(tox_options, TOX_SAVEDATA_TYPE_TOX_SAVE);
|
2021-12-05 20:07:27 +08:00
|
|
|
|
2022-02-19 11:24:01 +08:00
|
|
|
Tox *tox = tox_new(tox_options, nullptr);
|
|
|
|
tox_options_free(tox_options);
|
2022-03-25 03:26:57 +08:00
|
|
|
if (tox == nullptr) {
|
|
|
|
// Tox save was invalid, we're finished here
|
2022-04-03 01:10:09 +08:00
|
|
|
return;
|
2022-03-25 03:26:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// verify that the file can be saved again
|
|
|
|
std::vector<uint8_t> new_savedata(tox_get_savedata_size(tox));
|
|
|
|
tox_get_savedata(tox, new_savedata.data());
|
2021-12-05 20:07:27 +08:00
|
|
|
|
2022-02-19 11:24:01 +08:00
|
|
|
tox_kill(tox);
|
2022-04-03 01:10:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
|
|
|
{
|
|
|
|
Fuzz_Data input{data, size};
|
|
|
|
TestSaveDataLoading(input);
|
2022-02-19 11:24:01 +08:00
|
|
|
return 0; // Non-zero return values are reserved for future use.
|
2021-12-05 20:07:27 +08:00
|
|
|
}
|