Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix errors on error paths found by oomer. #1464

Merged
merged 1 commit into from
May 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions auto_tests/run_auto_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static void iterate_all_wait(uint32_t tox_count, Tox **toxes, State *state, uint
}

/* Also actually sleep a little, to allow for local network processing */
c_sleep(20);
c_sleep(5);
}

static uint64_t get_state_clock_callback(Mono_Time *mono_time, void *user_data)
Expand All @@ -63,6 +63,9 @@ static void run_auto_test(uint32_t tox_count, void test(Tox **toxes, State *stat
Tox **toxes = (Tox **)calloc(tox_count, sizeof(Tox *));
State *state = (State *)calloc(tox_count, sizeof(State));

ck_assert(toxes != nullptr);
ck_assert(state != nullptr);

for (uint32_t i = 0; i < tox_count; i++) {
state[i].index = i;
toxes[i] = tox_new_log(nullptr, nullptr, &state[i].index);
Expand All @@ -82,7 +85,9 @@ static void run_auto_test(uint32_t tox_count, void test(Tox **toxes, State *stat

uint8_t public_key[TOX_PUBLIC_KEY_SIZE];
tox_self_get_public_key(toxes[j], public_key);
tox_friend_add_norequest(toxes[i], public_key, nullptr);
Tox_Err_Friend_Add err;
tox_friend_add_norequest(toxes[i], public_key, &err);
ck_assert(err == TOX_ERR_FRIEND_ADD_OK);
}
}
} else {
Expand All @@ -93,7 +98,9 @@ static void run_auto_test(uint32_t tox_count, void test(Tox **toxes, State *stat
if (i != j) {
uint8_t public_key[TOX_PUBLIC_KEY_SIZE];
tox_self_get_public_key(toxes[j], public_key);
tox_friend_add_norequest(toxes[i], public_key, nullptr);
Tox_Err_Friend_Add err;
tox_friend_add_norequest(toxes[i], public_key, &err);
ck_assert(err == TOX_ERR_FRIEND_ADD_OK);
}
}
}
Expand All @@ -105,7 +112,9 @@ static void run_auto_test(uint32_t tox_count, void test(Tox **toxes, State *stat
const uint16_t dht_port = tox_self_get_udp_port(toxes[0], nullptr);

for (uint32_t i = 1; i < tox_count; i++) {
tox_bootstrap(toxes[i], "localhost", dht_port, dht_key, nullptr);
Tox_Err_Bootstrap err;
tox_bootstrap(toxes[i], "localhost", dht_port, dht_key, &err);
ck_assert(err == TOX_ERR_BOOTSTRAP_OK);
}

do {
Expand Down
5 changes: 4 additions & 1 deletion auto_tests/tox_one_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ static void test_one(void)

uint32_t index[] = { 1, 2 };
Tox *tox1 = tox_new_log(nullptr, nullptr, &index[0]);
ck_assert(tox1 != nullptr);
set_random_name_and_status_message(tox1, name, status_message);
Tox *tox2 = tox_new_log(nullptr, nullptr, &index[1]);
ck_assert(tox2 != nullptr);
set_random_name_and_status_message(tox2, name2, status_message2);

uint8_t address[TOX_ADDRESS_SIZE];
Expand All @@ -49,7 +51,7 @@ static void test_one(void)
ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_OWN_KEY, "Adding own address worked.");

tox_self_get_address(tox2, address);
uint8_t message[TOX_MAX_FRIEND_REQUEST_LENGTH + 1];
uint8_t message[TOX_MAX_FRIEND_REQUEST_LENGTH + 1] = {0};
ret = tox_friend_add(tox1, address, nullptr, 0, &error);
ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_NULL, "Sending request with no message worked.");
ret = tox_friend_add(tox1, address, message, 0, &error);
Expand Down Expand Up @@ -85,6 +87,7 @@ static void test_one(void)
Tox_Err_New err_n;

struct Tox_Options *options = tox_options_new(nullptr);
ck_assert(options != nullptr);
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
tox_options_set_savedata_data(options, data, save_size);
tox2 = tox_new_log(options, &err_n, &index[1]);
Expand Down
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/docker/tox-bootstrapd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c8bb5365e2cd01dab8d10a0d9c2e8f8e3be0996062151fbf95bf6304a0f1ecf1 /usr/local/bin/tox-bootstrapd
e7b6d31485b5e1561659be08f3e3ef003cef186042d7e0fe2ef48cf341932b5a /usr/local/bin/tox-bootstrapd
24 changes: 24 additions & 0 deletions other/bootstrap_daemon/docker/update-sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

set -eux

docker_build() {
tar c $(git ls-files) | docker build -f other/bootstrap_daemon/docker/Dockerfile -t toxchat/bootstrap-node -
}

# Run Docker build once. If it succeeds, we're good.
if docker_build; then
exit 0
fi

# We're not good. Run it again, but now capture the output.
OUTPUT=$(docker_build || true 2>&1)

if echo "$OUTPUT" | grep '/usr/local/bin/tox-bootstrapd: FAILED'; then
# This is a checksum warning, so we need to update it.
IMAGE=$(echo "$OUTPUT" | grep '^ ---> [0-9a-f]*$' | grep -o '[0-9a-f]*$' | tail -n1)
docker run --rm "$IMAGE" sha256sum /usr/local/bin/tox-bootstrapd > other/bootstrap_daemon/docker/tox-bootstrapd.sha256
fi

# Run once last time to complete the build.
docker_build
4 changes: 2 additions & 2 deletions toxav/ring_buffer_test.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "ring_buffer.h"

#include <gtest/gtest.h>

#include <algorithm>
#include <cassert>
#include <vector>

#include <gtest/gtest.h>

namespace {

template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions toxav/rtp_test.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "rtp.h"

#include "../toxcore/crypto_core.h"

#include <gtest/gtest.h>

#include "../toxcore/crypto_core.h"

namespace {

RTPHeader random_header() {
Expand Down
5 changes: 5 additions & 0 deletions toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -2721,6 +2721,11 @@ DHT *new_dht(const Logger *log, Mono_Time *mono_time, Networking_Core *net, bool
dht->dht_ping_array = ping_array_new(DHT_PING_ARRAY_SIZE, PING_TIMEOUT);
dht->dht_harden_ping_array = ping_array_new(DHT_PING_ARRAY_SIZE, PING_TIMEOUT);

if (dht->dht_ping_array == nullptr || dht->dht_harden_ping_array == nullptr) {
kill_dht(dht);
return nullptr;
}

for (uint32_t i = 0; i < DHT_FAKE_FRIEND_NUMBER; ++i) {
uint8_t random_public_key_bytes[CRYPTO_PUBLIC_KEY_SIZE];
uint8_t random_secret_key_bytes[CRYPTO_SECRET_KEY_SIZE];
Expand Down
4 changes: 2 additions & 2 deletions toxcore/Messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -1999,8 +1999,8 @@ Messenger *new_messenger(Mono_Time *mono_time, Messenger_Options *options, unsig
m->net_crypto = new_net_crypto(m->log, m->mono_time, m->dht, &options->proxy_info);

if (m->net_crypto == nullptr) {
kill_networking(m->net);
kill_dht(m->dht);
kill_networking(m->net);
friendreq_kill(m->fr);
logger_kill(m->log);
free(m);
Expand All @@ -2012,7 +2012,7 @@ Messenger *new_messenger(Mono_Time *mono_time, Messenger_Options *options, unsig
m->onion_c = new_onion_client(m->mono_time, m->net_crypto);
m->fr_c = new_friend_connections(m->mono_time, m->onion_c, options->local_discovery_enabled);

if (!(m->onion && m->onion_a && m->onion_c)) {
if (!(m->onion && m->onion_a && m->onion_c && m->fr_c)) {
kill_friend_connections(m->fr_c);
kill_onion(m->onion);
kill_onion_announce(m->onion_a);
Expand Down
6 changes: 3 additions & 3 deletions toxcore/crypto_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
#include "config.h"
#endif

#include "ccompat.h"
#include "crypto_core.h"

#include <stdlib.h>
#include <string.h>

#include "ccompat.h"
#include "crypto_core.h"

#ifndef VANILLA_NACL
/* We use libsodium by default. */
#include <sodium.h>
Expand Down
2 changes: 0 additions & 2 deletions toxcore/crypto_core_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
#include <windows.h>
#include <wincrypt.h>
#elif defined(HAVE_EXPLICIT_BZERO)
#include <string.h>
#endif
#endif

Expand Down
4 changes: 2 additions & 2 deletions toxcore/crypto_core_test.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "crypto_core.h"

#include <gtest/gtest.h>

#include <algorithm>
#include <vector>

#include <gtest/gtest.h>

namespace {

enum {
Expand Down
4 changes: 4 additions & 0 deletions toxcore/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ Ping *ping_new(const Mono_Time *mono_time, DHT *dht)

void ping_kill(Ping *ping)
{
if (ping == nullptr) {
return;
}

networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_REQUEST, nullptr, nullptr);
networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_RESPONSE, nullptr, nullptr);
ping_array_kill(ping->ping_array);
Expand Down
4 changes: 4 additions & 0 deletions toxcore/ping_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ static void clear_entry(Ping_Array *array, uint32_t index)

void ping_array_kill(Ping_Array *array)
{
if (array == nullptr) {
return;
}

while (array->last_deleted != array->last_added) {
const uint32_t index = array->last_deleted % array->total_size;
clear_entry(array, index);
Expand Down
3 changes: 2 additions & 1 deletion toxcore/ping_array_test.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "ping_array.h"

#include <gtest/gtest.h>

#include <memory>

#include <gtest/gtest.h>
#include "mono_time.h"

namespace {
Expand Down
Loading