diff options
author | iphydf <iphydf@users.noreply.github.com> | 2017-01-20 21:16:55 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2017-01-28 20:49:12 +0000 |
commit | 6ae33c16cf9e37fda85d70c78b3c2779eb8ca21a (patch) | |
tree | 99c3a8c26e02039b515bb6f57d2797d1cdf77c1d /toxcore/onion_client.c | |
parent | 895de7ef26e7617769f2271345e414545c2581f8 (diff) |
Add VLA compatibility macro for C89-ish compilers.
Diffstat (limited to 'toxcore/onion_client.c')
-rw-r--r-- | toxcore/onion_client.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index d324dbf2..a20d3d70 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -681,7 +681,7 @@ static int handle_announce_response(void *object, IP_Port source, const uint8_t | |||
681 | return 1; | 681 | return 1; |
682 | } | 682 | } |
683 | 683 | ||
684 | uint8_t plain[1 + ONION_PING_ID_SIZE + len_nodes]; | 684 | VLA(uint8_t, plain, 1 + ONION_PING_ID_SIZE + len_nodes); |
685 | int len = -1; | 685 | int len = -1; |
686 | 686 | ||
687 | if (num == 0) { | 687 | if (num == 0) { |
@@ -699,7 +699,7 @@ static int handle_announce_response(void *object, IP_Port source, const uint8_t | |||
699 | length - (1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE), plain); | 699 | length - (1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE), plain); |
700 | } | 700 | } |
701 | 701 | ||
702 | if ((uint32_t)len != sizeof(plain)) { | 702 | if ((uint32_t)len != SIZEOF_VLA(plain)) { |
703 | return 1; | 703 | return 1; |
704 | } | 704 | } |
705 | 705 | ||
@@ -739,20 +739,20 @@ static int handle_data_response(void *object, IP_Port source, const uint8_t *pac | |||
739 | return 1; | 739 | return 1; |
740 | } | 740 | } |
741 | 741 | ||
742 | uint8_t temp_plain[length - ONION_DATA_RESPONSE_MIN_SIZE]; | 742 | VLA(uint8_t, temp_plain, length - ONION_DATA_RESPONSE_MIN_SIZE); |
743 | int len = decrypt_data(packet + 1 + CRYPTO_NONCE_SIZE, onion_c->temp_secret_key, packet + 1, | 743 | int len = decrypt_data(packet + 1 + CRYPTO_NONCE_SIZE, onion_c->temp_secret_key, packet + 1, |
744 | packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE, | 744 | packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE, |
745 | length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE), temp_plain); | 745 | length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE), temp_plain); |
746 | 746 | ||
747 | if ((uint32_t)len != sizeof(temp_plain)) { | 747 | if ((uint32_t)len != SIZEOF_VLA(temp_plain)) { |
748 | return 1; | 748 | return 1; |
749 | } | 749 | } |
750 | 750 | ||
751 | uint8_t plain[sizeof(temp_plain) - DATA_IN_RESPONSE_MIN_SIZE]; | 751 | VLA(uint8_t, plain, SIZEOF_VLA(temp_plain) - DATA_IN_RESPONSE_MIN_SIZE); |
752 | len = decrypt_data(temp_plain, onion_c->c->self_secret_key, packet + 1, temp_plain + CRYPTO_PUBLIC_KEY_SIZE, | 752 | len = decrypt_data(temp_plain, onion_c->c->self_secret_key, packet + 1, temp_plain + CRYPTO_PUBLIC_KEY_SIZE, |
753 | sizeof(temp_plain) - CRYPTO_PUBLIC_KEY_SIZE, plain); | 753 | SIZEOF_VLA(temp_plain) - CRYPTO_PUBLIC_KEY_SIZE, plain); |
754 | 754 | ||
755 | if ((uint32_t)len != sizeof(plain)) { | 755 | if ((uint32_t)len != SIZEOF_VLA(plain)) { |
756 | return 1; | 756 | return 1; |
757 | } | 757 | } |
758 | 758 | ||
@@ -761,7 +761,7 @@ static int handle_data_response(void *object, IP_Port source, const uint8_t *pac | |||
761 | } | 761 | } |
762 | 762 | ||
763 | return onion_c->Onion_Data_Handlers[plain[0]].function(onion_c->Onion_Data_Handlers[plain[0]].object, temp_plain, plain, | 763 | return onion_c->Onion_Data_Handlers[plain[0]].function(onion_c->Onion_Data_Handlers[plain[0]].object, temp_plain, plain, |
764 | sizeof(plain), userdata); | 764 | SIZEOF_VLA(plain), userdata); |
765 | } | 765 | } |
766 | 766 | ||
767 | #define DHTPK_DATA_MIN_LENGTH (1 + sizeof(uint64_t) + CRYPTO_PUBLIC_KEY_SIZE) | 767 | #define DHTPK_DATA_MIN_LENGTH (1 + sizeof(uint64_t) + CRYPTO_PUBLIC_KEY_SIZE) |
@@ -899,12 +899,12 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data, | |||
899 | uint8_t nonce[CRYPTO_NONCE_SIZE]; | 899 | uint8_t nonce[CRYPTO_NONCE_SIZE]; |
900 | random_nonce(nonce); | 900 | random_nonce(nonce); |
901 | 901 | ||
902 | uint8_t packet[DATA_IN_RESPONSE_MIN_SIZE + length]; | 902 | VLA(uint8_t, packet, DATA_IN_RESPONSE_MIN_SIZE + length); |
903 | memcpy(packet, onion_c->c->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 903 | memcpy(packet, onion_c->c->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
904 | int len = encrypt_data(onion_c->friends_list[friend_num].real_public_key, onion_c->c->self_secret_key, nonce, data, | 904 | int len = encrypt_data(onion_c->friends_list[friend_num].real_public_key, onion_c->c->self_secret_key, nonce, data, |
905 | length, packet + CRYPTO_PUBLIC_KEY_SIZE); | 905 | length, packet + CRYPTO_PUBLIC_KEY_SIZE); |
906 | 906 | ||
907 | if ((uint32_t)len + CRYPTO_PUBLIC_KEY_SIZE != sizeof(packet)) { | 907 | if ((uint32_t)len + CRYPTO_PUBLIC_KEY_SIZE != SIZEOF_VLA(packet)) { |
908 | return -1; | 908 | return -1; |
909 | } | 909 | } |
910 | 910 | ||
@@ -919,7 +919,7 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data, | |||
919 | 919 | ||
920 | uint8_t o_packet[ONION_MAX_PACKET_SIZE]; | 920 | uint8_t o_packet[ONION_MAX_PACKET_SIZE]; |
921 | len = create_data_request(o_packet, sizeof(o_packet), onion_c->friends_list[friend_num].real_public_key, | 921 | len = create_data_request(o_packet, sizeof(o_packet), onion_c->friends_list[friend_num].real_public_key, |
922 | list_nodes[good_nodes[i]].data_public_key, nonce, packet, sizeof(packet)); | 922 | list_nodes[good_nodes[i]].data_public_key, nonce, packet, SIZEOF_VLA(packet)); |
923 | 923 | ||
924 | if (len == -1) { | 924 | if (len == -1) { |
925 | continue; | 925 | continue; |
@@ -953,19 +953,19 @@ static int send_dht_dhtpk(const Onion_Client *onion_c, int friend_num, const uin | |||
953 | uint8_t nonce[CRYPTO_NONCE_SIZE]; | 953 | uint8_t nonce[CRYPTO_NONCE_SIZE]; |
954 | random_nonce(nonce); | 954 | random_nonce(nonce); |
955 | 955 | ||
956 | uint8_t temp[DATA_IN_RESPONSE_MIN_SIZE + CRYPTO_NONCE_SIZE + length]; | 956 | VLA(uint8_t, temp, DATA_IN_RESPONSE_MIN_SIZE + CRYPTO_NONCE_SIZE + length); |
957 | memcpy(temp, onion_c->c->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 957 | memcpy(temp, onion_c->c->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
958 | memcpy(temp + CRYPTO_PUBLIC_KEY_SIZE, nonce, CRYPTO_NONCE_SIZE); | 958 | memcpy(temp + CRYPTO_PUBLIC_KEY_SIZE, nonce, CRYPTO_NONCE_SIZE); |
959 | int len = encrypt_data(onion_c->friends_list[friend_num].real_public_key, onion_c->c->self_secret_key, nonce, data, | 959 | int len = encrypt_data(onion_c->friends_list[friend_num].real_public_key, onion_c->c->self_secret_key, nonce, data, |
960 | length, temp + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE); | 960 | length, temp + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE); |
961 | 961 | ||
962 | if ((uint32_t)len + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE != sizeof(temp)) { | 962 | if ((uint32_t)len + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE != SIZEOF_VLA(temp)) { |
963 | return -1; | 963 | return -1; |
964 | } | 964 | } |
965 | 965 | ||
966 | uint8_t packet[MAX_CRYPTO_REQUEST_SIZE]; | 966 | uint8_t packet[MAX_CRYPTO_REQUEST_SIZE]; |
967 | len = create_request(onion_c->dht->self_public_key, onion_c->dht->self_secret_key, packet, | 967 | len = create_request(onion_c->dht->self_public_key, onion_c->dht->self_secret_key, packet, |
968 | onion_c->friends_list[friend_num].dht_public_key, temp, sizeof(temp), CRYPTO_PACKET_DHTPK); | 968 | onion_c->friends_list[friend_num].dht_public_key, temp, SIZEOF_VLA(temp), CRYPTO_PACKET_DHTPK); |
969 | 969 | ||
970 | if (len == -1) { | 970 | if (len == -1) { |
971 | return -1; | 971 | return -1; |