summaryrefslogtreecommitdiff
path: root/toxcore/DHT.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2020-05-02 20:49:41 +0100
committeriphydf <iphydf@users.noreply.github.com>2020-05-02 21:47:08 +0100
commit2570ddcb17fdf5bea56c6bc1c5c2d04ba2068ee7 (patch)
tree621dd5a3953ad786650e50fdba2787009c78df95 /toxcore/DHT.c
parente057bae563e133dbab7381ebbe1dc10f93d6eb4f (diff)
Fix errors on error paths found by oomer.
* Use-after-free because we free network before dht in one case. * Various unchecked allocs in tests (not so important). * We used to not check whether ping arrays were actually allocated in DHT. * `ping_kill` and `ping_array_kill` used to crash when passing NULL. Also: * Added an assert in all public API functions to ensure tox isn't NULL. The error message you get from that is a bit nicer than "Segmentation fault" when clients (or our tests) do things wrong. * Decreased the sleep time in iterate_all_wait from 20ms to 5ms. Everything seems to still work with 5ms, and this greatly decreases the amount of time spent per test run, making oomer run much faster.
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r--toxcore/DHT.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 7525e695..b3017259 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -2721,6 +2721,11 @@ DHT *new_dht(const Logger *log, Mono_Time *mono_time, Networking_Core *net, bool
2721 dht->dht_ping_array = ping_array_new(DHT_PING_ARRAY_SIZE, PING_TIMEOUT); 2721 dht->dht_ping_array = ping_array_new(DHT_PING_ARRAY_SIZE, PING_TIMEOUT);
2722 dht->dht_harden_ping_array = ping_array_new(DHT_PING_ARRAY_SIZE, PING_TIMEOUT); 2722 dht->dht_harden_ping_array = ping_array_new(DHT_PING_ARRAY_SIZE, PING_TIMEOUT);
2723 2723
2724 if (dht->dht_ping_array == nullptr || dht->dht_harden_ping_array == nullptr) {
2725 kill_dht(dht);
2726 return nullptr;
2727 }
2728
2724 for (uint32_t i = 0; i < DHT_FAKE_FRIEND_NUMBER; ++i) { 2729 for (uint32_t i = 0; i < DHT_FAKE_FRIEND_NUMBER; ++i) {
2725 uint8_t random_public_key_bytes[CRYPTO_PUBLIC_KEY_SIZE]; 2730 uint8_t random_public_key_bytes[CRYPTO_PUBLIC_KEY_SIZE];
2726 uint8_t random_secret_key_bytes[CRYPTO_SECRET_KEY_SIZE]; 2731 uint8_t random_secret_key_bytes[CRYPTO_SECRET_KEY_SIZE];