Skip to content

Commit

Permalink
Merge branch 'master' into noiseIK_2023_PR
Browse files Browse the repository at this point in the history
  • Loading branch information
goldroom committed Mar 22, 2024
2 parents 21b9126 + 0ec4978 commit 0ee531b
Show file tree
Hide file tree
Showing 30 changed files with 966 additions and 759 deletions.
2 changes: 1 addition & 1 deletion auto_tests/group_message_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ static void group_private_message_handler(const Tox_Event_Group_Private_Message

const uint32_t groupnumber = tox_event_group_private_message_get_group_number(event);
const uint32_t peer_id = tox_event_group_private_message_get_peer_id(event);
const Tox_Message_Type type = tox_event_group_private_message_get_type(event);
const Tox_Message_Type type = tox_event_group_private_message_get_message_type(event);
const uint8_t *message = tox_event_group_private_message_get_message(event);
const size_t length = tox_event_group_private_message_get_message_length(event);
const Tox_Group_Message_Id pseudo_msg_id = tox_event_group_private_message_get_message_id(event);
Expand Down
26 changes: 13 additions & 13 deletions other/event_tooling/generate_event_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ int main(int argc, char** argv) {
{
EventTypeTrivial{"uint32_t", "group_number"},
EventTypeTrivial{"uint32_t", "peer_id"},
EventTypeByteRange{"name", "name_length", "length"}, // the latter two are ideally the same
EventTypeByteRange{"name", "name_length", "name_length"},
}
},
{
Expand All @@ -702,7 +702,7 @@ int main(int argc, char** argv) {
{
EventTypeTrivial{"uint32_t", "group_number"},
EventTypeTrivial{"uint32_t", "peer_id"},
EventTypeByteRange{"topic", "topic_length", "length"}, // the latter two are ideally the same
EventTypeByteRange{"topic", "topic_length", "topic_length"},
}
},
{
Expand Down Expand Up @@ -737,16 +737,16 @@ int main(int argc, char** argv) {
"Group_Password",
{
EventTypeTrivial{"uint32_t", "group_number"},
EventTypeByteRange{"password", "password_length", "length"}, // the latter two are ideally the same
EventTypeByteRange{"password", "password_length", "password_length"},
}
},
{
"Group_Message",
{
EventTypeTrivial{"uint32_t", "group_number"},
EventTypeTrivial{"uint32_t", "peer_id"},
EventTypeTrivial{"Tox_Message_Type", "type"},
EventTypeByteRange{"message", "message_length", "length"}, // the latter two are ideally the same
EventTypeTrivial{"Tox_Message_Type", "message_type"},
EventTypeByteRange{"message", "message_length", "message_length"},
EventTypeTrivial{"uint32_t", "message_id"},
}
},
Expand All @@ -755,8 +755,8 @@ int main(int argc, char** argv) {
{
EventTypeTrivial{"uint32_t", "group_number"},
EventTypeTrivial{"uint32_t", "peer_id"},
EventTypeTrivial{"Tox_Message_Type", "type"},
EventTypeByteRange{"message", "message_length", "length"}, // the latter two are ideally the same
EventTypeTrivial{"Tox_Message_Type", "message_type"},
EventTypeByteRange{"message", "message_length", "message_length"},
EventTypeTrivial{"uint32_t", "message_id"},
}
},
Expand All @@ -765,23 +765,23 @@ int main(int argc, char** argv) {
{
EventTypeTrivial{"uint32_t", "group_number"},
EventTypeTrivial{"uint32_t", "peer_id"},
EventTypeByteRange{"data", "data_length", "length"}, // the latter two are ideally the same
EventTypeByteRange{"data", "data_length", "data_length"},
}
},
{
"Group_Custom_Private_Packet",
{
EventTypeTrivial{"uint32_t", "group_number"},
EventTypeTrivial{"uint32_t", "peer_id"},
EventTypeByteRange{"data", "data_length", "length"}, // the latter two are ideally the same
EventTypeByteRange{"data", "data_length", "data_length"},
}
},
{
"Group_Invite",
{
EventTypeTrivial{"uint32_t", "friend_number"},
EventTypeByteRange{"invite_data", "invite_data_length", "length"}, // the latter two are ideally the same
EventTypeByteRange{"group_name", "group_name_length", "group_name_length"}, // they are :)
EventTypeByteRange{"invite_data", "invite_data_length", "invite_data_length"},
EventTypeByteRange{"group_name", "group_name_length", "group_name_length"},
}
},
{
Expand All @@ -797,8 +797,8 @@ int main(int argc, char** argv) {
EventTypeTrivial{"uint32_t", "group_number"},
EventTypeTrivial{"uint32_t", "peer_id"},
EventTypeTrivial{"Tox_Group_Exit_Type", "exit_type"},
EventTypeByteRange{"name", "name_length", "name_length"}, // they are :)
EventTypeByteRange{"part_message", "part_message_length", "part_message_length"}, // they are :)
EventTypeByteRange{"name", "name_length", "name_length"},
EventTypeByteRange{"part_message", "part_message_length", "part_message_length"},
}
},
{
Expand Down
1 change: 1 addition & 0 deletions testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ sh_test(
args = ["$(locations %s)" % f for f in CIMPLE_FILES] + [
"-Wno-boolean-return",
"-Wno-callback-names",
"-Wno-enum-from-int",
"+RTS",
"-N4",
"-RTS",
Expand Down
8 changes: 6 additions & 2 deletions testing/fuzzing/bootstrap_fuzz_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ void TestBootstrap(Fuzz_Data &input)

Ptr<Tox_Options> opts(tox_options_new(nullptr), tox_options_free);
assert(opts != nullptr);
tox_options_set_operating_system(opts.get(), sys.sys.get());

tox_options_set_log_callback(opts.get(),
[](Tox *tox, Tox_Log_Level level, const char *file, uint32_t line, const char *func,
Expand Down Expand Up @@ -134,8 +133,12 @@ void TestBootstrap(Fuzz_Data &input)
tox_options_set_tcp_port(opts.get(), 33445);
}

Tox_Options_Testing tox_options_testing;
tox_options_testing.operating_system = sys.sys.get();

Tox_Err_New error_new;
Tox *tox = tox_new(opts.get(), &error_new);
Tox_Err_New_Testing error_new_testing;
Tox *tox = tox_new_testing(opts.get(), &error_new, &tox_options_testing, &error_new_testing);

if (tox == nullptr) {
// It might fail, because some I/O happens in tox_new, and the fuzzer
Expand All @@ -144,6 +147,7 @@ void TestBootstrap(Fuzz_Data &input)
}

assert(error_new == TOX_ERR_NEW_OK);
assert(error_new_testing == TOX_ERR_NEW_TESTING_OK);

uint8_t pub_key[TOX_PUBLIC_KEY_SIZE] = {0};

Expand Down
8 changes: 6 additions & 2 deletions testing/fuzzing/e2e_fuzz_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ void TestEndToEnd(Fuzz_Data &input)

Ptr<Tox_Options> opts(tox_options_new(nullptr), tox_options_free);
assert(opts != nullptr);
tox_options_set_operating_system(opts.get(), sys.sys.get());
tox_options_set_local_discovery_enabled(opts.get(), false);

tox_options_set_log_callback(opts.get(),
Expand All @@ -151,8 +150,12 @@ void TestEndToEnd(Fuzz_Data &input)
}
});

Tox_Options_Testing tox_options_testing;
tox_options_testing.operating_system = sys.sys.get();

Tox_Err_New error_new;
Tox *tox = tox_new(opts.get(), &error_new);
Tox_Err_New_Testing error_new_testing;
Tox *tox = tox_new_testing(opts.get(), &error_new, &tox_options_testing, &error_new_testing);

if (tox == nullptr) {
// It might fail, because some I/O happens in tox_new, and the fuzzer
Expand All @@ -161,6 +164,7 @@ void TestEndToEnd(Fuzz_Data &input)
}

assert(error_new == TOX_ERR_NEW_OK);
assert(error_new_testing == TOX_ERR_NEW_TESTING_OK);

tox_events_init(tox);

Expand Down
1 change: 1 addition & 0 deletions testing/fuzzing/fuzz_support.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <vector>

#include "../../toxcore/tox.h"
#include "../../toxcore/tox_private.h"

struct Fuzz_Data {
static constexpr bool DEBUG = false;
Expand Down
12 changes: 8 additions & 4 deletions testing/fuzzing/protodump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,16 @@ void RecordBootstrap(const char *init, const char *bootstrap)
});

Tox_Err_New error_new;
Tox_Err_New_Testing error_new_testing;
Tox_Options_Testing tox_options_testing;

Record_System sys1(global, 4, "tox1"); // fair dice roll
tox_options_set_log_user_data(opts, &sys1);
tox_options_set_operating_system(opts, sys1.sys.get());
Tox *tox1 = tox_new(opts, &error_new);
tox_options_testing.operating_system = sys1.sys.get();
Tox *tox1 = tox_new_testing(opts, &error_new, &tox_options_testing, &error_new_testing);
assert(tox1 != nullptr);
assert(error_new == TOX_ERR_NEW_OK);
assert(error_new_testing == TOX_ERR_NEW_TESTING_OK);
std::array<uint8_t, TOX_ADDRESS_SIZE> address1;
tox_self_get_address(tox1, address1.data());
std::array<uint8_t, TOX_PUBLIC_KEY_SIZE> pk1;
Expand All @@ -211,10 +214,11 @@ void RecordBootstrap(const char *init, const char *bootstrap)

Record_System sys2(global, 5, "tox2"); // unfair dice roll
tox_options_set_log_user_data(opts, &sys2);
tox_options_set_operating_system(opts, sys2.sys.get());
Tox *tox2 = tox_new(opts, &error_new);
tox_options_testing.operating_system = sys2.sys.get();
Tox *tox2 = tox_new_testing(opts, &error_new, &tox_options_testing, &error_new_testing);
assert(tox2 != nullptr);
assert(error_new == TOX_ERR_NEW_OK);
assert(error_new_testing == TOX_ERR_NEW_TESTING_OK);
std::array<uint8_t, TOX_ADDRESS_SIZE> address2;
tox_self_get_address(tox2, address2.data());
std::array<uint8_t, TOX_PUBLIC_KEY_SIZE> pk2;
Expand Down
8 changes: 6 additions & 2 deletions testing/fuzzing/protodump_reduce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ void TestEndToEnd(Fuzz_Data &input)

Ptr<Tox_Options> opts(tox_options_new(nullptr), tox_options_free);
assert(opts != nullptr);
tox_options_set_operating_system(opts.get(), sys.sys.get());
tox_options_set_local_discovery_enabled(opts.get(), false);

Tox_Options_Testing tox_options_testing;
tox_options_testing.operating_system = sys.sys.get();

tox_options_set_log_callback(opts.get(),
[](Tox *tox, Tox_Log_Level level, const char *file, uint32_t line, const char *func,
const char *message, void *user_data) {
Expand All @@ -156,7 +158,8 @@ void TestEndToEnd(Fuzz_Data &input)
});

Tox_Err_New error_new;
Tox *tox = tox_new(opts.get(), &error_new);
Tox_Err_New_Testing error_new_testing;
Tox *tox = tox_new_testing(opts.get(), &error_new, &tox_options_testing, &error_new_testing);

if (tox == nullptr) {
// It might fail, because some I/O happens in tox_new, and the fuzzer
Expand All @@ -165,6 +168,7 @@ void TestEndToEnd(Fuzz_Data &input)
}

assert(error_new == TOX_ERR_NEW_OK);
assert(error_new_testing == TOX_ERR_NEW_TESTING_OK);

tox_events_init(tox);

Expand Down
9 changes: 5 additions & 4 deletions testing/fuzzing/toxsave_fuzz_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ void TestSaveDataLoading(Fuzz_Data &input)
const size_t savedata_size = input.size();
CONSUME_OR_RETURN(const uint8_t *savedata, input, savedata_size);

Null_System sys;
tox_options_set_operating_system(tox_options, sys.sys.get());

// pass test data to Tox
tox_options_set_savedata_data(tox_options, savedata, savedata_size);
tox_options_set_savedata_type(tox_options, TOX_SAVEDATA_TYPE_TOX_SAVE);

Tox *tox = tox_new(tox_options, nullptr);
Tox_Options_Testing tox_options_testing;
Null_System sys;
tox_options_testing.operating_system = sys.sys.get();

Tox *tox = tox_new_testing(tox_options, nullptr, &tox_options_testing, nullptr);
tox_options_free(tox_options);
if (tox == nullptr) {
// Tox save was invalid, we're finished here
Expand Down
Loading

0 comments on commit 0ee531b

Please sign in to comment.