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 48dbcfe commit 24b5472
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
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
2 changes: 0 additions & 2 deletions testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
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 24b5472

Please sign in to comment.