/work/toxcore/group_moderation_fuzz_test.cc
Line | Count | Source |
1 | | #include "group_moderation.h" |
2 | | |
3 | | #include <cstddef> |
4 | | |
5 | | #include "../testing/support/public/fuzz_data.hh" |
6 | | #include "../testing/support/public/simulated_environment.hh" |
7 | | |
8 | | namespace { |
9 | | |
10 | | using tox::test::Fuzz_Data; |
11 | | using tox::test::SimulatedEnvironment; |
12 | | |
13 | | void TestModListUnpack(Fuzz_Data &input) |
14 | 17 | { |
15 | 17 | CONSUME1_OR_RETURN(const std::uint16_t, num_mods, input); |
16 | 16 | SimulatedEnvironment env{12345}; |
17 | 16 | auto c_mem = env.fake_memory().c_memory(); |
18 | 16 | Moderation mods{&c_mem}; |
19 | 16 | mod_list_unpack(&mods, input.data(), input.size(), num_mods); |
20 | 16 | mod_list_cleanup(&mods); |
21 | 16 | } |
22 | | |
23 | | void TestSanctionsListUnpack(Fuzz_Data &input) |
24 | 15 | { |
25 | 15 | Mod_Sanction sanctions[10]; |
26 | 15 | Mod_Sanction_Creds creds; |
27 | 15 | std::uint16_t processed_data_len; |
28 | 15 | sanctions_list_unpack(sanctions, &creds, 10, input.data(), input.size(), &processed_data_len); |
29 | 15 | } |
30 | | |
31 | | void TestSanctionCredsUnpack(Fuzz_Data &input) |
32 | 2 | { |
33 | 2 | CONSUME_OR_RETURN(const std::uint8_t *data, input, MOD_SANCTIONS_CREDS_SIZE); |
34 | 1 | Mod_Sanction_Creds creds; |
35 | 1 | sanctions_creds_unpack(&creds, data); |
36 | 1 | } |
37 | | |
38 | | } // namespace |
39 | | |
40 | | extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t *data, std::size_t size); |
41 | | extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t *data, std::size_t size) |
42 | 2.69k | { |
43 | 2.69k | tox::test::fuzz_select_target<TestModListUnpack, TestSanctionsListUnpack, |
44 | 2.69k | TestSanctionCredsUnpack>(data, size); |
45 | 2.69k | return 0; |
46 | 2.69k | } |