Skip to content

Commit

Permalink
fix: Ensure we have allocators available for the error paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Sep 11, 2023
1 parent 0cef46e commit a987d11
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def _create_cmake(self):
self._cmake = CMake(self)
self._cmake.definitions["AUTOTEST"] = self.options.with_tests
self._cmake.definitions["BUILD_MISC_TESTS"] = self.options.with_tests
self._cmake.definitions["TEST_TIMEOUT_SECONDS"] = "300"
self._cmake.definitions["TEST_TIMEOUT_SECONDS"] = "60"
self._cmake.definitions["CMAKE_CTEST_ARGUMENTS"] = "--repeat,until-pass:6"

self._cmake.definitions[
"CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = self.options.shared
Expand Down
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/docker/tox-bootstrapd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
619d28e6ecd0dbfbf8727753d44aa7eb1d8baa53cfcd4067f426141b4c132784 /usr/local/bin/tox-bootstrapd
bd6954cbbff8d2b6cc1fe5681a016ff42a0400da35c2b50d11550443c8dce6af /usr/local/bin/tox-bootstrapd
13 changes: 7 additions & 6 deletions testing/fuzzing/bootstrap_harness.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ void setup_callbacks(Tox_Dispatch *dispatch)

void TestBootstrap(Fuzz_Data &input)
{
// Null system for regularly working memory allocations needed in
// tox_events_equal.
Null_System null_sys;
Fuzz_System sys(input);

Ptr<Tox_Options> opts(tox_options_new(nullptr), tox_options_free);
Expand Down Expand Up @@ -154,11 +157,9 @@ void TestBootstrap(Fuzz_Data &input)

uint8_t pub_key[TOX_PUBLIC_KEY_SIZE] = {0};

const bool udp_success = tox_bootstrap(tox, "127.0.0.2", 33446, pub_key, nullptr);
assert(udp_success);

const bool tcp_success = tox_add_tcp_relay(tox, "127.0.0.2", 33446, pub_key, nullptr);
assert(tcp_success);
// These may fail, but that's ok. We ignore their return values.
tox_bootstrap(tox, "127.0.0.2", 33446, pub_key, nullptr);
tox_add_tcp_relay(tox, "127.0.0.2", 33446, pub_key, nullptr);

tox_events_init(tox);

Expand All @@ -169,7 +170,7 @@ void TestBootstrap(Fuzz_Data &input)
while (input.size > 0) {
Tox_Err_Events_Iterate error_iterate;
Tox_Events *events = tox_events_iterate(tox, true, &error_iterate);
assert(tox_events_equal(sys.sys.get(), events, events));
assert(tox_events_equal(null_sys.sys.get(), events, events));
tox_dispatch_invoke(dispatch, events, tox, nullptr);
tox_events_free(events);
// Move the clock forward a decent amount so all the time-based checks
Expand Down
4 changes: 4 additions & 0 deletions toxcore/group_chats.c
Original file line number Diff line number Diff line change
Expand Up @@ -7483,6 +7483,10 @@ int gc_group_load(GC_Session *c, Bin_Unpack *bu)
chat->last_ping_interval = tm;
chat->friend_connection_id = -1;

// Initialise these first, because we may need to log/dealloc things on cleanup.
chat->moderation.log = m->log;
chat->moderation.mem = m->mem;

if (!gc_load_unpack_group(chat, bu)) {
LOGGER_ERROR(chat->log, "Failed to unpack group");
return -1;
Expand Down
4 changes: 3 additions & 1 deletion toxcore/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,9 @@ int32_t net_getipport(const Memory *mem, const char *node, IP_Port **res, int to
{
// Try parsing as IP address first.
IP_Port parsed = {{{0}}};
// Initialise to nullptr. In error paths, at least we initialise the out
// parameter.
*res = nullptr;

if (addr_parse_ip(node, &parsed.ip)) {
IP_Port *tmp = (IP_Port *)mem_alloc(mem, sizeof(IP_Port));
Expand Down Expand Up @@ -1800,7 +1803,6 @@ int32_t net_getipport(const Memory *mem, const char *node, IP_Port **res, int to
// It's not an IP address, so now we try doing a DNS lookup.
struct addrinfo *infos;
const int ret = getaddrinfo(node, nullptr, nullptr, &infos);
*res = nullptr;

if (ret != 0) {
return -1;
Expand Down

0 comments on commit a987d11

Please sign in to comment.