From 88b90c82259f86470cf6eba8684e8d9b4cd61bc3 Mon Sep 17 00:00:00 2001 From: iphydf Date: Sun, 3 May 2020 01:09:06 +0100 Subject: Fix a bug in savedata loading when malloc fails. Also added a bunch of asserts to tests where they don't check allocs. --- toxcore/DHT.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'toxcore') diff --git a/toxcore/DHT.c b/toxcore/DHT.c index b3017259..7c9263cd 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -2917,6 +2917,12 @@ static State_Load_Status dht_load_state_callback(void *outer, const uint8_t *dat // Copy to loaded_clients_list dht->loaded_nodes_list = (Node_format *)calloc(MAX_SAVED_DHT_NODES, sizeof(Node_format)); + if (dht->loaded_nodes_list == nullptr) { + LOGGER_ERROR(dht->log, "could not allocate %u nodes", MAX_SAVED_DHT_NODES); + dht->loaded_num_nodes = 0; + break; + } + const int num = unpack_nodes(dht->loaded_nodes_list, MAX_SAVED_DHT_NODES, nullptr, data, length, 0); if (num > 0) { -- cgit v1.2.3