fix: Ensure we have allocators available for the error paths.

This commit is contained in:
iphydf 2023-09-11 10:51:20 +00:00
parent 48dbcfebc0
commit 24b54722ae
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
5 changed files with 15 additions and 10 deletions

View File

@ -1 +1 @@
619d28e6ecd0dbfbf8727753d44aa7eb1d8baa53cfcd4067f426141b4c132784 /usr/local/bin/tox-bootstrapd
bd6954cbbff8d2b6cc1fe5681a016ff42a0400da35c2b50d11550443c8dce6af /usr/local/bin/tox-bootstrapd

View File

@ -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",

View File

@ -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);
@ -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

View File

@ -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;

View File

@ -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;