summaryrefslogtreecommitdiff
path: root/toxcore/DHT.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2017-01-20 21:16:55 +0000
committeriphydf <iphydf@users.noreply.github.com>2017-01-28 20:49:12 +0000
commit6ae33c16cf9e37fda85d70c78b3c2779eb8ca21a (patch)
tree99c3a8c26e02039b515bb6f57d2797d1cdf77c1d /toxcore/DHT.c
parent895de7ef26e7617769f2271345e414545c2581f8 (diff)
Add VLA compatibility macro for C89-ish compilers.
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r--toxcore/DHT.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 5f3a1d07..227c6175 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -361,7 +361,7 @@ static int pack_ip_port(uint8_t *data, uint16_t length, const IP_Port *ip_port)
361static int DHT_create_packet(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE], 361static int DHT_create_packet(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
362 const uint8_t *shared_key, const uint8_t type, uint8_t *plain, size_t plain_length, uint8_t *packet) 362 const uint8_t *shared_key, const uint8_t type, uint8_t *plain, size_t plain_length, uint8_t *packet)
363{ 363{
364 uint8_t encrypted[plain_length + CRYPTO_MAC_SIZE]; 364 VLA(uint8_t, encrypted, plain_length + CRYPTO_MAC_SIZE);
365 uint8_t nonce[CRYPTO_NONCE_SIZE]; 365 uint8_t nonce[CRYPTO_NONCE_SIZE];
366 366
367 random_nonce(nonce); 367 random_nonce(nonce);
@@ -1264,7 +1264,7 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public
1264 Node_format nodes_list[MAX_SENT_NODES]; 1264 Node_format nodes_list[MAX_SENT_NODES];
1265 uint32_t num_nodes = get_close_nodes(dht, client_id, nodes_list, 0, LAN_ip(ip_port.ip) == 0, 1); 1265 uint32_t num_nodes = get_close_nodes(dht, client_id, nodes_list, 0, LAN_ip(ip_port.ip) == 0, 1);
1266 1266
1267 uint8_t plain[1 + Node_format_size * MAX_SENT_NODES + length]; 1267 VLA(uint8_t, plain, 1 + Node_format_size * MAX_SENT_NODES + length);
1268 1268
1269 int nodes_length = 0; 1269 int nodes_length = 0;
1270 1270
@@ -1279,13 +1279,13 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public
1279 plain[0] = num_nodes; 1279 plain[0] = num_nodes;
1280 memcpy(plain + 1 + nodes_length, sendback_data, length); 1280 memcpy(plain + 1 + nodes_length, sendback_data, length);
1281 1281
1282 uint8_t data[1 + nodes_length + length + 1 + CRYPTO_PUBLIC_KEY_SIZE 1282 VLA(uint8_t, data, 1 + nodes_length + length + 1 + CRYPTO_PUBLIC_KEY_SIZE
1283 + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE]; 1283 + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE);
1284 1284
1285 int len = DHT_create_packet(dht->self_public_key, shared_encryption_key, NET_PACKET_SEND_NODES_IPV6, 1285 int len = DHT_create_packet(dht->self_public_key, shared_encryption_key, NET_PACKET_SEND_NODES_IPV6,
1286 plain, 1 + nodes_length + length, data); 1286 plain, 1 + nodes_length + length, data);
1287 1287
1288 if (len != sizeof(data)) { 1288 if (len != SIZEOF_VLA(data)) {
1289 return -1; 1289 return -1;
1290 } 1290 }
1291 1291
@@ -1375,7 +1375,7 @@ static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *pa
1375 return 1; 1375 return 1;
1376 } 1376 }
1377 1377
1378 uint8_t plain[1 + data_size + sizeof(uint64_t)]; 1378 VLA(uint8_t, plain, 1 + data_size + sizeof(uint64_t));
1379 uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; 1379 uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
1380 DHT_get_shared_key_sent(dht, shared_key, packet + 1); 1380 DHT_get_shared_key_sent(dht, shared_key, packet + 1);
1381 int len = decrypt_data_symmetric( 1381 int len = decrypt_data_symmetric(
@@ -1385,7 +1385,7 @@ static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *pa
1385 1 + data_size + sizeof(uint64_t) + CRYPTO_MAC_SIZE, 1385 1 + data_size + sizeof(uint64_t) + CRYPTO_MAC_SIZE,
1386 plain); 1386 plain);
1387 1387
1388 if ((unsigned int)len != sizeof(plain)) { 1388 if ((unsigned int)len != SIZEOF_VLA(plain)) {
1389 return 1; 1389 return 1;
1390 } 1390 }
1391 1391
@@ -1598,8 +1598,8 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
1598 uint64_t temp_time = unix_time(); 1598 uint64_t temp_time = unix_time();
1599 1599
1600 uint32_t num_nodes = 0; 1600 uint32_t num_nodes = 0;
1601 Client_data *client_list[list_count * 2]; 1601 VLA(Client_data *, client_list, list_count * 2);
1602 IPPTsPng *assoc_list[list_count * 2]; 1602 VLA(IPPTsPng *, assoc_list, list_count * 2);
1603 unsigned int sort = 0; 1603 unsigned int sort = 0;
1604 bool sort_ok = 0; 1604 bool sort_ok = 0;
1605 1605
@@ -2247,12 +2247,12 @@ static int send_hardening_getnode_res(const DHT *dht, const Node_format *sendto,
2247 } 2247 }
2248 2248
2249 uint8_t packet[MAX_CRYPTO_REQUEST_SIZE]; 2249 uint8_t packet[MAX_CRYPTO_REQUEST_SIZE];
2250 uint8_t data[1 + CRYPTO_PUBLIC_KEY_SIZE + nodes_data_length]; 2250 VLA(uint8_t, data, 1 + CRYPTO_PUBLIC_KEY_SIZE + nodes_data_length);
2251 data[0] = CHECK_TYPE_GETNODE_RES; 2251 data[0] = CHECK_TYPE_GETNODE_RES;
2252 memcpy(data + 1, queried_client_id, CRYPTO_PUBLIC_KEY_SIZE); 2252 memcpy(data + 1, queried_client_id, CRYPTO_PUBLIC_KEY_SIZE);
2253 memcpy(data + 1 + CRYPTO_PUBLIC_KEY_SIZE, nodes_data, nodes_data_length); 2253 memcpy(data + 1 + CRYPTO_PUBLIC_KEY_SIZE, nodes_data, nodes_data_length);
2254 int len = create_request(dht->self_public_key, dht->self_secret_key, packet, sendto->public_key, data, 2254 int len = create_request(dht->self_public_key, dht->self_secret_key, packet, sendto->public_key, data,
2255 sizeof(data), CRYPTO_PACKET_HARDENING); 2255 SIZEOF_VLA(data), CRYPTO_PACKET_HARDENING);
2256 2256
2257 if (len == -1) { 2257 if (len == -1) {
2258 return -1; 2258 return -1;