From 24b54722aed65b02f1e921f08f8d31d68f92a45a Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 11 Sep 2023 10:51:20 +0000 Subject: [PATCH] fix: Ensure we have allocators available for the error paths. --- other/bootstrap_daemon/docker/tox-bootstrapd.sha256 | 2 +- testing/BUILD.bazel | 2 -- testing/fuzzing/bootstrap_harness.cc | 13 +++++++------ toxcore/group_chats.c | 4 ++++ toxcore/network.c | 4 +++- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 61ec91a6..1ac47b2d 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -619d28e6ecd0dbfbf8727753d44aa7eb1d8baa53cfcd4067f426141b4c132784 /usr/local/bin/tox-bootstrapd +bd6954cbbff8d2b6cc1fe5681a016ff42a0400da35c2b50d11550443c8dce6af /usr/local/bin/tox-bootstrapd diff --git a/testing/BUILD.bazel b/testing/BUILD.bazel index 68e89a15..4f275033 100644 --- a/testing/BUILD.bazel +++ b/testing/BUILD.bazel @@ -15,9 +15,7 @@ sh_test( args = ["$(locations %s)" % f for f in CIMPLE_FILES] + [ "-Wno-boolean-return", "-Wno-callback-names", - "-Wno-callgraph", "-Wno-enum-names", - "-Wno-type-check", "+RTS", "-N3", "-RTS", diff --git a/testing/fuzzing/bootstrap_harness.cc b/testing/fuzzing/bootstrap_harness.cc index 9ffb69d1..2e9639e2 100644 --- a/testing/fuzzing/bootstrap_harness.cc +++ b/testing/fuzzing/bootstrap_harness.cc @@ -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 opts(tox_options_new(nullptr), tox_options_free); @@ -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); @@ -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 diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c index 23eca0a9..ac10e8b1 100644 --- a/toxcore/group_chats.c +++ b/toxcore/group_chats.c @@ -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; diff --git a/toxcore/network.c b/toxcore/network.c index 90b3d2d9..cc04cde7 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -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)); @@ -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;