summaryrefslogtreecommitdiff
path: root/toxcore/TCP_server.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/TCP_server.c
parent895de7ef26e7617769f2271345e414545c2581f8 (diff)
Add VLA compatibility macro for C89-ish compilers.
Diffstat (limited to 'toxcore/TCP_server.c')
-rw-r--r--toxcore/TCP_server.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c
index 47ad9933..10f64d38 100644
--- a/toxcore/TCP_server.c
+++ b/toxcore/TCP_server.c
@@ -325,7 +325,7 @@ int read_packet_TCP_secure_connection(Socket sock, uint16_t *next_packet_length,
325 return -1; 325 return -1;
326 } 326 }
327 327
328 uint8_t data_encrypted[*next_packet_length]; 328 VLA(uint8_t, data_encrypted, *next_packet_length);
329 int len_packet = read_TCP_packet(sock, data_encrypted, *next_packet_length); 329 int len_packet = read_TCP_packet(sock, data_encrypted, *next_packet_length);
330 330
331 if (len_packet != *next_packet_length) { 331 if (len_packet != *next_packet_length) {
@@ -458,18 +458,18 @@ static int write_packet_TCP_secure_connection(TCP_Secure_Connection *con, const
458 } 458 }
459 } 459 }
460 460
461 uint8_t packet[sizeof(uint16_t) + length + CRYPTO_MAC_SIZE]; 461 VLA(uint8_t, packet, sizeof(uint16_t) + length + CRYPTO_MAC_SIZE);
462 462
463 uint16_t c_length = htons(length + CRYPTO_MAC_SIZE); 463 uint16_t c_length = htons(length + CRYPTO_MAC_SIZE);
464 memcpy(packet, &c_length, sizeof(uint16_t)); 464 memcpy(packet, &c_length, sizeof(uint16_t));
465 int len = encrypt_data_symmetric(con->shared_key, con->sent_nonce, data, length, packet + sizeof(uint16_t)); 465 int len = encrypt_data_symmetric(con->shared_key, con->sent_nonce, data, length, packet + sizeof(uint16_t));
466 466
467 if ((unsigned int)len != (sizeof(packet) - sizeof(uint16_t))) { 467 if ((unsigned int)len != (SIZEOF_VLA(packet) - sizeof(uint16_t))) {
468 return -1; 468 return -1;
469 } 469 }
470 470
471 if (priority) { 471 if (priority) {
472 len = sendpriority ? send(con->sock, (const char *)packet, sizeof(packet), MSG_NOSIGNAL) : 0; 472 len = sendpriority ? send(con->sock, (const char *)packet, SIZEOF_VLA(packet), MSG_NOSIGNAL) : 0;
473 473
474 if (len <= 0) { 474 if (len <= 0) {
475 len = 0; 475 len = 0;
@@ -477,14 +477,14 @@ static int write_packet_TCP_secure_connection(TCP_Secure_Connection *con, const
477 477
478 increment_nonce(con->sent_nonce); 478 increment_nonce(con->sent_nonce);
479 479
480 if ((unsigned int)len == sizeof(packet)) { 480 if ((unsigned int)len == SIZEOF_VLA(packet)) {
481 return 1; 481 return 1;
482 } 482 }
483 483
484 return add_priority(con, packet, sizeof(packet), len); 484 return add_priority(con, packet, SIZEOF_VLA(packet), len);
485 } 485 }
486 486
487 len = send(con->sock, (const char *)packet, sizeof(packet), MSG_NOSIGNAL); 487 len = send(con->sock, (const char *)packet, SIZEOF_VLA(packet), MSG_NOSIGNAL);
488 488
489 if (len <= 0) { 489 if (len <= 0) {
490 return 0; 490 return 0;
@@ -492,12 +492,12 @@ static int write_packet_TCP_secure_connection(TCP_Secure_Connection *con, const
492 492
493 increment_nonce(con->sent_nonce); 493 increment_nonce(con->sent_nonce);
494 494
495 if ((unsigned int)len == sizeof(packet)) { 495 if ((unsigned int)len == SIZEOF_VLA(packet)) {
496 return 1; 496 return 1;
497 } 497 }
498 498
499 memcpy(con->last_packet, packet, sizeof(packet)); 499 memcpy(con->last_packet, packet, SIZEOF_VLA(packet));
500 con->last_packet_length = sizeof(packet); 500 con->last_packet_length = SIZEOF_VLA(packet);
501 con->last_packet_sent = len; 501 con->last_packet_sent = len;
502 return 1; 502 return 1;
503} 503}
@@ -737,12 +737,12 @@ static int handle_TCP_oob_send(TCP_Server *TCP_server, uint32_t con_id, const ui
737 int other_index = get_TCP_connection_index(TCP_server, public_key); 737 int other_index = get_TCP_connection_index(TCP_server, public_key);
738 738
739 if (other_index != -1) { 739 if (other_index != -1) {
740 uint8_t resp_packet[1 + CRYPTO_PUBLIC_KEY_SIZE + length]; 740 VLA(uint8_t, resp_packet, 1 + CRYPTO_PUBLIC_KEY_SIZE + length);
741 resp_packet[0] = TCP_PACKET_OOB_RECV; 741 resp_packet[0] = TCP_PACKET_OOB_RECV;
742 memcpy(resp_packet + 1, con->public_key, CRYPTO_PUBLIC_KEY_SIZE); 742 memcpy(resp_packet + 1, con->public_key, CRYPTO_PUBLIC_KEY_SIZE);
743 memcpy(resp_packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, data, length); 743 memcpy(resp_packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, data, length);
744 write_packet_TCP_secure_connection(&TCP_server->accepted_connection_array[other_index], resp_packet, 744 write_packet_TCP_secure_connection(&TCP_server->accepted_connection_array[other_index], resp_packet,
745 sizeof(resp_packet), 0); 745 SIZEOF_VLA(resp_packet), 0);
746 } 746 }
747 747
748 return 0; 748 return 0;
@@ -800,11 +800,11 @@ static int handle_onion_recv_1(void *object, IP_Port dest, const uint8_t *data,
800 return 1; 800 return 1;
801 } 801 }
802 802
803 uint8_t packet[1 + length]; 803 VLA(uint8_t, packet, 1 + length);
804 memcpy(packet + 1, data, length); 804 memcpy(packet + 1, data, length);
805 packet[0] = TCP_PACKET_ONION_RESPONSE; 805 packet[0] = TCP_PACKET_ONION_RESPONSE;
806 806
807 if (write_packet_TCP_secure_connection(con, packet, sizeof(packet), 0) != 1) { 807 if (write_packet_TCP_secure_connection(con, packet, SIZEOF_VLA(packet), 0) != 1) {
808 return 1; 808 return 1;
809 } 809 }
810 810
@@ -931,7 +931,7 @@ static int handle_TCP_packet(TCP_Server *TCP_server, uint32_t con_id, const uint
931 931
932 uint32_t index = con->connections[c_id].index; 932 uint32_t index = con->connections[c_id].index;
933 uint8_t other_c_id = con->connections[c_id].other_id + NUM_RESERVED_PORTS; 933 uint8_t other_c_id = con->connections[c_id].other_id + NUM_RESERVED_PORTS;
934 uint8_t new_data[length]; 934 VLA(uint8_t, new_data, length);
935 memcpy(new_data, data, length); 935 memcpy(new_data, data, length);
936 new_data[0] = other_c_id; 936 new_data[0] = other_c_id;
937 int ret = write_packet_TCP_secure_connection(&TCP_server->accepted_connection_array[index], new_data, length, 0); 937 int ret = write_packet_TCP_secure_connection(&TCP_server->accepted_connection_array[index], new_data, length, 0);