summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2020-05-03 01:09:06 +0100
committeriphydf <iphydf@users.noreply.github.com>2020-05-03 14:13:48 +0000
commit88b90c82259f86470cf6eba8684e8d9b4cd61bc3 (patch)
tree90e052389ffacec791019a096837a670e205b225
parent7b758f66dbc550fa52ed66fd7f8b81f8ed37a94e (diff)
Fix a bug in savedata loading when malloc fails.
Also added a bunch of asserts to tests where they don't check allocs.
-rw-r--r--.restyled.yaml5
-rw-r--r--auto_tests/TCP_test.c1
-rw-r--r--auto_tests/conference_invite_merge_test.c2
-rw-r--r--auto_tests/conference_peer_nick_test.c1
-rw-r--r--auto_tests/conference_test.c2
-rw-r--r--auto_tests/encryptsave_test.c1
-rw-r--r--auto_tests/file_saving_test.c8
-rwxr-xr-xother/astyle/format-source8
-rw-r--r--other/bootstrap_daemon/docker/tox-bootstrapd.sha2562
-rw-r--r--toxav/toxav.c8
-rw-r--r--toxcore/DHT.c6
11 files changed, 33 insertions, 11 deletions
diff --git a/.restyled.yaml b/.restyled.yaml
new file mode 100644
index 00000000..722ff510
--- /dev/null
+++ b/.restyled.yaml
@@ -0,0 +1,5 @@
1---
2restylers:
3 - astyle:
4 arguments: ["--options=other/astyle/astylerc"]
5 - prettier-yaml
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c
index 9206e265..8a109317 100644
--- a/auto_tests/TCP_test.c
+++ b/auto_tests/TCP_test.c
@@ -185,6 +185,7 @@ struct sec_TCP_con {
185static struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s, Mono_Time *mono_time) 185static struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s, Mono_Time *mono_time)
186{ 186{
187 struct sec_TCP_con *sec_c = (struct sec_TCP_con *)malloc(sizeof(struct sec_TCP_con)); 187 struct sec_TCP_con *sec_c = (struct sec_TCP_con *)malloc(sizeof(struct sec_TCP_con));
188 ck_assert(sec_c != nullptr);
188 Socket sock = net_socket(net_family_ipv6, TOX_SOCK_STREAM, TOX_PROTO_TCP); 189 Socket sock = net_socket(net_family_ipv6, TOX_SOCK_STREAM, TOX_PROTO_TCP);
189 190
190 IP_Port ip_port_loopback; 191 IP_Port ip_port_loopback;
diff --git a/auto_tests/conference_invite_merge_test.c b/auto_tests/conference_invite_merge_test.c
index e7ec499c..21445525 100644
--- a/auto_tests/conference_invite_merge_test.c
+++ b/auto_tests/conference_invite_merge_test.c
@@ -91,9 +91,11 @@ static void reload(Tox **toxes, State *state, uint32_t n)
91 ck_assert(state[n].save_state != nullptr); 91 ck_assert(state[n].save_state != nullptr);
92 92
93 struct Tox_Options *const options = tox_options_new(nullptr); 93 struct Tox_Options *const options = tox_options_new(nullptr);
94 ck_assert(options != nullptr);
94 tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE); 95 tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
95 tox_options_set_savedata_data(options, state[n].save_state, state[n].save_size); 96 tox_options_set_savedata_data(options, state[n].save_state, state[n].save_size);
96 toxes[n] = tox_new_log(options, nullptr, &state[n].index); 97 toxes[n] = tox_new_log(options, nullptr, &state[n].index);
98 ck_assert(toxes[n] != nullptr);
97 tox_options_free(options); 99 tox_options_free(options);
98 100
99 set_mono_time_callback(toxes[n], &state[n]); 101 set_mono_time_callback(toxes[n], &state[n]);
diff --git a/auto_tests/conference_peer_nick_test.c b/auto_tests/conference_peer_nick_test.c
index 9d10a8a9..749f9098 100644
--- a/auto_tests/conference_peer_nick_test.c
+++ b/auto_tests/conference_peer_nick_test.c
@@ -68,6 +68,7 @@ static void rebuild_peer_list(Tox *tox)
68 "failed to get conference peer %u's name size (conference = %u): err = %d", peer_number, conference_number, err); 68 "failed to get conference peer %u's name size (conference = %u): err = %d", peer_number, conference_number, err);
69 69
70 uint8_t *const name = (uint8_t *)malloc(size); 70 uint8_t *const name = (uint8_t *)malloc(size);
71 ck_assert(name != nullptr);
71 tox_conference_peer_get_name(tox, conference_number, peer_number, name, &err); 72 tox_conference_peer_get_name(tox, conference_number, peer_number, name, &err);
72 ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK, 73 ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
73 "failed to get conference peer %u's name (conference = %u): err = %d", peer_number, conference_number, err); 74 "failed to get conference peer %u's name (conference = %u): err = %d", peer_number, conference_number, err);
diff --git a/auto_tests/conference_test.c b/auto_tests/conference_test.c
index ec88c82a..11a7bb06 100644
--- a/auto_tests/conference_test.c
+++ b/auto_tests/conference_test.c
@@ -250,9 +250,11 @@ static void run_conference_tests(Tox **toxes, State *state)
250 for (uint32_t i = 0; i < NUM_GROUP_TOX; ++i) { 250 for (uint32_t i = 0; i < NUM_GROUP_TOX; ++i) {
251 if (restarting[i]) { 251 if (restarting[i]) {
252 struct Tox_Options *const options = tox_options_new(nullptr); 252 struct Tox_Options *const options = tox_options_new(nullptr);
253 ck_assert(options != nullptr);
253 tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE); 254 tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
254 tox_options_set_savedata_data(options, save[i], save_size[i]); 255 tox_options_set_savedata_data(options, save[i], save_size[i]);
255 toxes[i] = tox_new_log(options, nullptr, &state[i].index); 256 toxes[i] = tox_new_log(options, nullptr, &state[i].index);
257 ck_assert(toxes[i] != nullptr);
256 tox_options_free(options); 258 tox_options_free(options);
257 free(save[i]); 259 free(save[i]);
258 260
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c
index 19574d16..ccb1ee88 100644
--- a/auto_tests/encryptsave_test.c
+++ b/auto_tests/encryptsave_test.c
@@ -76,6 +76,7 @@ static void test_save_friend(void)
76 ck_assert_msg(tox_is_data_encrypted(enc_data), "magic number missing"); 76 ck_assert_msg(tox_is_data_encrypted(enc_data), "magic number missing");
77 77
78 struct Tox_Options *options = tox_options_new(nullptr); 78 struct Tox_Options *options = tox_options_new(nullptr);
79 ck_assert(options != nullptr);
79 tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE); 80 tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
80 tox_options_set_savedata_data(options, enc_data, size2); 81 tox_options_set_savedata_data(options, enc_data, size2);
81 82
diff --git a/auto_tests/file_saving_test.c b/auto_tests/file_saving_test.c
index 7faa6b20..cdcce95f 100644
--- a/auto_tests/file_saving_test.c
+++ b/auto_tests/file_saving_test.c
@@ -64,6 +64,7 @@ static void save_data_encrypted(void)
64static void load_data_decrypted(void) 64static void load_data_decrypted(void)
65{ 65{
66 FILE *f = fopen(savefile, "r"); 66 FILE *f = fopen(savefile, "r");
67 ck_assert(f != nullptr);
67 fseek(f, 0, SEEK_END); 68 fseek(f, 0, SEEK_END);
68 int64_t size = ftell(f); 69 int64_t size = ftell(f);
69 fseek(f, 0, SEEK_SET); 70 fseek(f, 0, SEEK_SET);
@@ -71,7 +72,9 @@ static void load_data_decrypted(void)
71 ck_assert_msg(0 <= size && size <= UINT_MAX, "file size out of range"); 72 ck_assert_msg(0 <= size && size <= UINT_MAX, "file size out of range");
72 73
73 uint8_t *cipher = (uint8_t *)malloc(size); 74 uint8_t *cipher = (uint8_t *)malloc(size);
75 ck_assert(cipher != nullptr);
74 uint8_t *clear = (uint8_t *)malloc(size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH); 76 uint8_t *clear = (uint8_t *)malloc(size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH);
77 ck_assert(clear != nullptr);
75 size_t read_value = fread(cipher, sizeof(*cipher), size, f); 78 size_t read_value = fread(cipher, sizeof(*cipher), size, f);
76 printf("Read read_value = %u of %u\n", (unsigned)read_value, (unsigned)size); 79 printf("Read read_value = %u of %u\n", (unsigned)read_value, (unsigned)size);
77 80
@@ -81,6 +84,7 @@ static void load_data_decrypted(void)
81 "Could not decrypt, error code %d.", derr); 84 "Could not decrypt, error code %d.", derr);
82 85
83 struct Tox_Options *options = tox_options_new(nullptr); 86 struct Tox_Options *options = tox_options_new(nullptr);
87 ck_assert(options != nullptr);
84 88
85 tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE); 89 tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
86 90
@@ -101,10 +105,10 @@ static void load_data_decrypted(void)
101 ck_assert_msg(strcmp((const char *)readname, name) == 0, 105 ck_assert_msg(strcmp((const char *)readname, name) == 0,
102 "name returned by tox_self_get_name does not match expected result"); 106 "name returned by tox_self_get_name does not match expected result");
103 107
104 free(cipher); 108 tox_kill(t);
105 free(clear); 109 free(clear);
110 free(cipher);
106 fclose(f); 111 fclose(f);
107 tox_kill(t);
108} 112}
109 113
110int main(void) 114int main(void)
diff --git a/other/astyle/format-source b/other/astyle/format-source
index 711823d8..193e335c 100755
--- a/other/astyle/format-source
+++ b/other/astyle/format-source
@@ -49,7 +49,7 @@ apidsl_request() {
49} 49}
50 50
51apidsl_curl() { 51apidsl_curl() {
52 echo "apidsl_curl $@" >&2 52 echo "apidsl_curl $*" >&2
53 apidsl_request "c" <( 53 apidsl_request "c" <(
54 apidsl_request "parse" <( 54 apidsl_request "parse" <(
55 perl -0777 -pe "$TO_JSON" $1)) | perl -0777 -pe "$FROM_JSON" 55 perl -0777 -pe "$TO_JSON" $1)) | perl -0777 -pe "$FROM_JSON"
@@ -68,12 +68,12 @@ set -x
68 68
69wait; wait; wait; wait; wait; wait; wait 69wait; wait; wait; wait; wait; wait; wait
70 70
71if grep '<unresolved>' */*.h; then 71if grep '<unresolved>' ./*/*.h; then
72 echo "error: some apidsl references were unresolved" 72 echo "error: some apidsl references were unresolved"
73 exit 1 73 exit 1
74fi 74fi
75 75
76CC_SOURCES=`find . '(' -name '*.cc' ')'` 76CC_SOURCES=$(find . '(' -name '*.cc' ')')
77CC_SOURCES="$CC_SOURCES toxcore/crypto_core.c" 77CC_SOURCES="$CC_SOURCES toxcore/crypto_core.c"
78CC_SOURCES="$CC_SOURCES toxcore/ping_array.c" 78CC_SOURCES="$CC_SOURCES toxcore/ping_array.c"
79 79
@@ -91,7 +91,7 @@ FIND="$FIND -and -not -wholename './super_donators/*'"
91FIND="$FIND -and -not -wholename './third_party/*'" 91FIND="$FIND -and -not -wholename './third_party/*'"
92FIND="$FIND -and -not -wholename './toxencryptsave/crypto_pwhash*'" 92FIND="$FIND -and -not -wholename './toxencryptsave/crypto_pwhash*'"
93 93
94C_SOURCES=`eval "$FIND"` 94C_SOURCES=$(eval "$FIND")
95 95
96$ASTYLE -n --options=other/astyle/astylerc $C_SOURCES 96$ASTYLE -n --options=other/astyle/astylerc $C_SOURCES
97 97
diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256
index 4d02d38f..82043e0d 100644
--- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256
+++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256
@@ -1 +1 @@
89df21d6a19a1b6652db5b7e6e9f65ad5f8be8abdca9f58645548b9e0c9383e3 /usr/local/bin/tox-bootstrapd 79c4f7416951d024f95d08e7fc48e127181b7465935cc75b9b3e0ab001bd43b4 /usr/local/bin/tox-bootstrapd
diff --git a/toxav/toxav.c b/toxav/toxav.c
index 3dbe2cff..0ecf8259 100644
--- a/toxav/toxav.c
+++ b/toxav/toxav.c
@@ -755,7 +755,7 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc
755 goto RETURN; 755 goto RETURN;
756 } 756 }
757 757
758 { /* Encode and send */ 758 { /* Encode and send */
759 if (ac_reconfigure_encoder(call->audio, call->audio_bit_rate * 1000, sampling_rate, channels) != 0) { 759 if (ac_reconfigure_encoder(call->audio, call->audio_bit_rate * 1000, sampling_rate, channels) != 0) {
760 pthread_mutex_unlock(call->mutex_audio); 760 pthread_mutex_unlock(call->mutex_audio);
761 rc = TOXAV_ERR_SEND_FRAME_INVALID; 761 rc = TOXAV_ERR_SEND_FRAME_INVALID;
@@ -896,7 +896,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u
896 896
897 // we start with I-frames (full frames) and then switch to normal mode later 897 // we start with I-frames (full frames) and then switch to normal mode later
898 898
899 { /* Encode */ 899 { /* Encode */
900 vpx_image_t img; 900 vpx_image_t img;
901 img.w = 0; 901 img.w = 0;
902 img.h = 0; 902 img.h = 0;
@@ -1323,7 +1323,7 @@ static bool call_prepare_transmission(ToxAVCall *call)
1323 /* Prepare bwc */ 1323 /* Prepare bwc */
1324 call->bwc = bwc_new(av->m, av->tox, call->friend_number, callback_bwc, call, av->toxav_mono_time); 1324 call->bwc = bwc_new(av->m, av->tox, call->friend_number, callback_bwc, call, av->toxav_mono_time);
1325 1325
1326 { /* Prepare audio */ 1326 { /* Prepare audio */
1327 call->audio = ac_new(av->toxav_mono_time, av->m->log, av, call->friend_number, av->acb, av->acb_user_data); 1327 call->audio = ac_new(av->toxav_mono_time, av->m->log, av, call->friend_number, av->acb, av->acb_user_data);
1328 1328
1329 if (!call->audio) { 1329 if (!call->audio) {
@@ -1339,7 +1339,7 @@ static bool call_prepare_transmission(ToxAVCall *call)
1339 goto FAILURE; 1339 goto FAILURE;
1340 } 1340 }
1341 } 1341 }
1342 { /* Prepare video */ 1342 { /* Prepare video */
1343 call->video = vc_new(av->toxav_mono_time, av->m->log, av, call->friend_number, av->vcb, av->vcb_user_data); 1343 call->video = vc_new(av->toxav_mono_time, av->m->log, av, call->friend_number, av->vcb, av->vcb_user_data);
1344 1344
1345 if (!call->video) { 1345 if (!call->video) {
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index b3017259..7c9263cd 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -2917,6 +2917,12 @@ static State_Load_Status dht_load_state_callback(void *outer, const uint8_t *dat
2917 // Copy to loaded_clients_list 2917 // Copy to loaded_clients_list
2918 dht->loaded_nodes_list = (Node_format *)calloc(MAX_SAVED_DHT_NODES, sizeof(Node_format)); 2918 dht->loaded_nodes_list = (Node_format *)calloc(MAX_SAVED_DHT_NODES, sizeof(Node_format));
2919 2919
2920 if (dht->loaded_nodes_list == nullptr) {
2921 LOGGER_ERROR(dht->log, "could not allocate %u nodes", MAX_SAVED_DHT_NODES);
2922 dht->loaded_num_nodes = 0;
2923 break;
2924 }
2925
2920 const int num = unpack_nodes(dht->loaded_nodes_list, MAX_SAVED_DHT_NODES, nullptr, data, length, 0); 2926 const int num = unpack_nodes(dht->loaded_nodes_list, MAX_SAVED_DHT_NODES, nullptr, data, length, 0);
2921 2927
2922 if (num > 0) { 2928 if (num > 0) {