diff options
author | zugz (tox) <mbays+tox@sdf.org> | 2020-04-26 00:00:00 +0000 |
---|---|---|
committer | zugz (tox) <mbays+tox@sdf.org> | 2020-04-26 00:00:00 +0000 |
commit | 8816e50ed708f10fd94c77f1e2ac9a1f9bc2e5dc (patch) | |
tree | 97a84ec531d7bd6e455ee2a1250c93a261ced767 | |
parent | 223f98d0b577124569788720cd3f87dafe868b39 (diff) |
Skip invalid TCP relays and DHT nodes when loading save data
-rw-r--r-- | auto_tests/save_compatibility_test.c | 3 | ||||
-rw-r--r-- | toxcore/Messenger.c | 13 |
2 files changed, 15 insertions, 1 deletions
diff --git a/auto_tests/save_compatibility_test.c b/auto_tests/save_compatibility_test.c index a32015b4..fffe2f6e 100644 --- a/auto_tests/save_compatibility_test.c +++ b/auto_tests/save_compatibility_test.c | |||
@@ -124,6 +124,9 @@ static void test_save_compatibility(const char *save_path) | |||
124 | ck_assert_msg(strncmp(tox_id_str, EXPECTED_TOX_ID, TOX_ADDRESS_SIZE * 2) == 0, | 124 | ck_assert_msg(strncmp(tox_id_str, EXPECTED_TOX_ID, TOX_ADDRESS_SIZE * 2) == 0, |
125 | "tox ids do not match, expected %s got %s", EXPECTED_TOX_ID, tox_id_str); | 125 | "tox ids do not match, expected %s got %s", EXPECTED_TOX_ID, tox_id_str); |
126 | 126 | ||
127 | /* Giving the tox a chance to error on iterate due to corrupted loaded structures */ | ||
128 | tox_iterate(tox, nullptr); | ||
129 | |||
127 | tox_kill(tox); | 130 | tox_kill(tox); |
128 | } | 131 | } |
129 | 132 | ||
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 93ed6495..9863018d 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -3160,7 +3160,14 @@ static uint8_t *save_tcp_relays(const Messenger *m, uint8_t *data) | |||
3160 | static State_Load_Status load_tcp_relays(Messenger *m, const uint8_t *data, uint32_t length) | 3160 | static State_Load_Status load_tcp_relays(Messenger *m, const uint8_t *data, uint32_t length) |
3161 | { | 3161 | { |
3162 | if (length != 0) { | 3162 | if (length != 0) { |
3163 | m->num_loaded_relays = unpack_nodes(m->loaded_relays, NUM_SAVED_TCP_RELAYS, nullptr, data, length, 1); | 3163 | const int num = unpack_nodes(m->loaded_relays, NUM_SAVED_TCP_RELAYS, nullptr, data, length, 1); |
3164 | |||
3165 | if (num == -1) { | ||
3166 | m->num_loaded_relays = 0; | ||
3167 | return STATE_LOAD_STATUS_CONTINUE; | ||
3168 | } | ||
3169 | |||
3170 | m->num_loaded_relays = num; | ||
3164 | m->has_added_relays = false; | 3171 | m->has_added_relays = false; |
3165 | } | 3172 | } |
3166 | 3173 | ||
@@ -3198,6 +3205,10 @@ static State_Load_Status load_path_nodes(Messenger *m, const uint8_t *data, uint | |||
3198 | if (length != 0) { | 3205 | if (length != 0) { |
3199 | const int num = unpack_nodes(nodes, NUM_SAVED_PATH_NODES, nullptr, data, length, 0); | 3206 | const int num = unpack_nodes(nodes, NUM_SAVED_PATH_NODES, nullptr, data, length, 0); |
3200 | 3207 | ||
3208 | if (num == -1) { | ||
3209 | return STATE_LOAD_STATUS_CONTINUE; | ||
3210 | } | ||
3211 | |||
3201 | for (int i = 0; i < num; ++i) { | 3212 | for (int i = 0; i < num; ++i) { |
3202 | onion_add_bs_path_node(m->onion_c, nodes[i].ip_port, nodes[i].public_key); | 3213 | onion_add_bs_path_node(m->onion_c, nodes[i].ip_port, nodes[i].public_key); |
3203 | } | 3214 | } |