summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auto_tests/TCP_test.c1
-rw-r--r--auto_tests/onion_test.c49
-rw-r--r--other/DHT_bootstrap.c9
-rw-r--r--testing/hstox/driver.c9
-rw-r--r--testing/irc_syncbot.c1
-rw-r--r--testing/nTox.c7
-rw-r--r--testing/tox_sync.c1
7 files changed, 70 insertions, 7 deletions
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c
index 4b6f6fa1..79d83800 100644
--- a/auto_tests/TCP_test.c
+++ b/auto_tests/TCP_test.c
@@ -137,6 +137,7 @@ START_TEST(test_basic)
137 ck_assert_msg(packet_resp_plain[0] == 1, "wrong packet id %u", packet_resp_plain[0]); 137 ck_assert_msg(packet_resp_plain[0] == 1, "wrong packet id %u", packet_resp_plain[0]);
138 ck_assert_msg(packet_resp_plain[1] == 0, "connection not refused %u", packet_resp_plain[1]); 138 ck_assert_msg(packet_resp_plain[1] == 0, "connection not refused %u", packet_resp_plain[1]);
139 ck_assert_msg(public_key_cmp(packet_resp_plain + 2, f_public_key) == 0, "key in packet wrong"); 139 ck_assert_msg(public_key_cmp(packet_resp_plain + 2, f_public_key) == 0, "key in packet wrong");
140 kill_sock(sock);
140 kill_TCP_server(tcp_s); 141 kill_TCP_server(tcp_s);
141} 142}
142END_TEST 143END_TEST
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c
index 32a2e381..61b358d6 100644
--- a/auto_tests/onion_test.c
+++ b/auto_tests/onion_test.c
@@ -298,17 +298,58 @@ static Onions *new_onions(uint16_t port)
298 IP ip = get_loopback(); 298 IP ip = get_loopback();
299 ip.ip6.uint8[15] = 1; 299 ip.ip6.uint8[15] = 1;
300 Onions *on = (Onions *)malloc(sizeof(Onions)); 300 Onions *on = (Onions *)malloc(sizeof(Onions));
301 DHT *dht = new_DHT(NULL, new_networking(NULL, ip, port), true); 301
302 if (!on) {
303 return NULL;
304 }
305
306 Networking_Core *net = new_networking(NULL, ip, port);
307
308 if (!net) {
309 free(on);
310 return NULL;
311 }
312
313 DHT *dht = new_DHT(NULL, net, true);
314
315 if (!dht) {
316 kill_networking(net);
317 free(on);
318 return NULL;
319 }
320
302 on->onion = new_onion(dht); 321 on->onion = new_onion(dht);
322
323 if (!on->onion) {
324 kill_DHT(dht);
325 kill_networking(net);
326 free(on);
327 return NULL;
328 }
329
303 on->onion_a = new_onion_announce(dht); 330 on->onion_a = new_onion_announce(dht);
331
332 if (!on->onion_a) {
333 kill_onion(on->onion);
334 kill_DHT(dht);
335 kill_networking(net);
336 free(on);
337 return NULL;
338 }
339
304 TCP_Proxy_Info inf = {{{0}}}; 340 TCP_Proxy_Info inf = {{{0}}};
305 on->onion_c = new_onion_client(new_net_crypto(NULL, dht, &inf)); 341 on->onion_c = new_onion_client(new_net_crypto(NULL, dht, &inf));
306 342
307 if (on->onion && on->onion_a && on->onion_c) { 343 if (!on->onion_c) {
308 return on; 344 kill_onion_announce(on->onion_a);
345 kill_onion(on->onion);
346 kill_DHT(dht);
347 kill_networking(net);
348 free(on);
349 return NULL;
309 } 350 }
310 351
311 return NULL; 352 return on;
312} 353}
313 354
314static void do_onions(Onions *on) 355static void do_onions(Onions *on)
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c
index b715181a..0e95805d 100644
--- a/other/DHT_bootstrap.c
+++ b/other/DHT_bootstrap.c
@@ -146,8 +146,13 @@ int main(int argc, char *argv[])
146 146
147#endif 147#endif
148 148
149 FILE *file; 149 const char *const public_id_filename = "PUBLIC_ID.txt";
150 file = fopen("PUBLIC_ID.txt", "w"); 150 FILE *file = fopen(public_id_filename, "w");
151
152 if (file == NULL) {
153 printf("Could not open file \"%s\" for writing. Exiting...\n", public_id_filename);
154 exit(1);
155 }
151 156
152 for (i = 0; i < 32; i++) { 157 for (i = 0; i < 32; i++) {
153 printf("%02hhX", dht->self_public_key[i]); 158 printf("%02hhX", dht->self_public_key[i]);
diff --git a/testing/hstox/driver.c b/testing/hstox/driver.c
index 442967bf..6d1b8e0e 100644
--- a/testing/hstox/driver.c
+++ b/testing/hstox/driver.c
@@ -58,6 +58,13 @@ static bool type_check(msgpack_packer *pk, msgpack_object req, int index,
58 return true; 58 return true;
59} 59}
60 60
61static int close_ptr(int *fd)
62{
63 if (fd && *fd >= 0) {
64 close(*fd);
65 }
66}
67
61static int write_sample_input(msgpack_object req) 68static int write_sample_input(msgpack_object req)
62{ 69{
63 static unsigned int n; 70 static unsigned int n;
@@ -70,7 +77,7 @@ static int write_sample_input(msgpack_object req)
70 memcpy(filename + strlen(filename) + name.size, ".mp", 4); 77 memcpy(filename + strlen(filename) + name.size, ".mp", 4);
71 memcpy(filename + strlen(filename), name.ptr, name.size); 78 memcpy(filename + strlen(filename), name.ptr, name.size);
72 79
73 int fd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); 80 int fd __attribute__((__cleanup__(close_ptr))) = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
74 81
75 if (fd < 0) 82 if (fd < 0)
76 // If we can't open the sample file, we just don't write it. 83 // If we can't open the sample file, we just don't write it.
diff --git a/testing/irc_syncbot.c b/testing/irc_syncbot.c
index 91267f84..f122094f 100644
--- a/testing/irc_syncbot.c
+++ b/testing/irc_syncbot.c
@@ -75,6 +75,7 @@ static int reconnect(void)
75 75
76 if (connect(new_sock, (struct sockaddr *)&addr, addrsize) != 0) { 76 if (connect(new_sock, (struct sockaddr *)&addr, addrsize) != 0) {
77 printf("error connect\n"); 77 printf("error connect\n");
78 close(new_sock);
78 return -1; 79 return -1;
79 } 80 }
80 81
diff --git a/testing/nTox.c b/testing/nTox.c
index 73038622..59872ee3 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -1261,6 +1261,13 @@ static void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uin
1261 pFile = fopen(filename, "wb"); 1261 pFile = fopen(filename, "wb");
1262 } 1262 }
1263 1263
1264 if (pFile == NULL) {
1265 char msg[512];
1266 sprintf(msg, "Could not open file \"%s\" for writing.", filename);
1267 new_lines(msg);
1268 return;
1269 }
1270
1264 fseek(pFile, position, SEEK_SET); 1271 fseek(pFile, position, SEEK_SET);
1265 1272
1266 if (fwrite(data, length, 1, pFile) != 1) { 1273 if (fwrite(data, length, 1, pFile) != 1) {
diff --git a/testing/tox_sync.c b/testing/tox_sync.c
index 10fc047e..954c64e1 100644
--- a/testing/tox_sync.c
+++ b/testing/tox_sync.c
@@ -95,6 +95,7 @@ static uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename)
95 strlen(filename), 0); 95 strlen(filename), 0);
96 96
97 if (filenum == -1) { 97 if (filenum == -1) {
98 fclose(tempfile);
98 return -1; 99 return -1;
99 } 100 }
100 101