diff options
author | iphydf <iphydf@users.noreply.github.com> | 2020-05-02 20:49:41 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2020-05-02 21:47:08 +0100 |
commit | 2570ddcb17fdf5bea56c6bc1c5c2d04ba2068ee7 (patch) | |
tree | 621dd5a3953ad786650e50fdba2787009c78df95 /toxcore/ping_array.c | |
parent | e057bae563e133dbab7381ebbe1dc10f93d6eb4f (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/ping_array.c')
-rw-r--r-- | toxcore/ping_array.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/toxcore/ping_array.c b/toxcore/ping_array.c index a93d48dd..201b507d 100644 --- a/toxcore/ping_array.c +++ b/toxcore/ping_array.c | |||
@@ -75,6 +75,10 @@ static void clear_entry(Ping_Array *array, uint32_t index) | |||
75 | 75 | ||
76 | void ping_array_kill(Ping_Array *array) | 76 | void ping_array_kill(Ping_Array *array) |
77 | { | 77 | { |
78 | if (array == nullptr) { | ||
79 | return; | ||
80 | } | ||
81 | |||
78 | while (array->last_deleted != array->last_added) { | 82 | while (array->last_deleted != array->last_added) { |
79 | const uint32_t index = array->last_deleted % array->total_size; | 83 | const uint32_t index = array->last_deleted % array->total_size; |
80 | clear_entry(array, index); | 84 | clear_entry(array, index); |