summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.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/Messenger.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/Messenger.c')
-rw-r--r--toxcore/Messenger.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 6b691ad8..82c31147 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -1999,8 +1999,8 @@ Messenger *new_messenger(Mono_Time *mono_time, Messenger_Options *options, unsig
1999 m->net_crypto = new_net_crypto(m->log, m->mono_time, m->dht, &options->proxy_info); 1999 m->net_crypto = new_net_crypto(m->log, m->mono_time, m->dht, &options->proxy_info);
2000 2000
2001 if (m->net_crypto == nullptr) { 2001 if (m->net_crypto == nullptr) {
2002 kill_networking(m->net);
2003 kill_dht(m->dht); 2002 kill_dht(m->dht);
2003 kill_networking(m->net);
2004 friendreq_kill(m->fr); 2004 friendreq_kill(m->fr);
2005 logger_kill(m->log); 2005 logger_kill(m->log);
2006 free(m); 2006 free(m);
@@ -2012,7 +2012,7 @@ Messenger *new_messenger(Mono_Time *mono_time, Messenger_Options *options, unsig
2012 m->onion_c = new_onion_client(m->mono_time, m->net_crypto); 2012 m->onion_c = new_onion_client(m->mono_time, m->net_crypto);
2013 m->fr_c = new_friend_connections(m->mono_time, m->onion_c, options->local_discovery_enabled); 2013 m->fr_c = new_friend_connections(m->mono_time, m->onion_c, options->local_discovery_enabled);
2014 2014
2015 if (!(m->onion && m->onion_a && m->onion_c)) { 2015 if (!(m->onion && m->onion_a && m->onion_c && m->fr_c)) {
2016 kill_friend_connections(m->fr_c); 2016 kill_friend_connections(m->fr_c);
2017 kill_onion(m->onion); 2017 kill_onion(m->onion);
2018 kill_onion_announce(m->onion_a); 2018 kill_onion_announce(m->onion_a);