diff options
Diffstat (limited to 'toxcore/net_crypto.c')
-rw-r--r-- | toxcore/net_crypto.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index cc3c5226..ecd0177c 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -903,12 +903,12 @@ static int send_data_packet(Net_Crypto *c, int crypt_connection_id, const uint8_ | |||
903 | } | 903 | } |
904 | 904 | ||
905 | pthread_mutex_lock(&conn->mutex); | 905 | pthread_mutex_lock(&conn->mutex); |
906 | uint8_t packet[1 + sizeof(uint16_t) + length + CRYPTO_MAC_SIZE]; | 906 | VLA(uint8_t, packet, 1 + sizeof(uint16_t) + length + CRYPTO_MAC_SIZE); |
907 | packet[0] = NET_PACKET_CRYPTO_DATA; | 907 | packet[0] = NET_PACKET_CRYPTO_DATA; |
908 | memcpy(packet + 1, conn->sent_nonce + (CRYPTO_NONCE_SIZE - sizeof(uint16_t)), sizeof(uint16_t)); | 908 | memcpy(packet + 1, conn->sent_nonce + (CRYPTO_NONCE_SIZE - sizeof(uint16_t)), sizeof(uint16_t)); |
909 | int len = encrypt_data_symmetric(conn->shared_key, conn->sent_nonce, data, length, packet + 1 + sizeof(uint16_t)); | 909 | int len = encrypt_data_symmetric(conn->shared_key, conn->sent_nonce, data, length, packet + 1 + sizeof(uint16_t)); |
910 | 910 | ||
911 | if (len + 1 + sizeof(uint16_t) != sizeof(packet)) { | 911 | if (len + 1 + sizeof(uint16_t) != SIZEOF_VLA(packet)) { |
912 | pthread_mutex_unlock(&conn->mutex); | 912 | pthread_mutex_unlock(&conn->mutex); |
913 | return -1; | 913 | return -1; |
914 | } | 914 | } |
@@ -916,7 +916,7 @@ static int send_data_packet(Net_Crypto *c, int crypt_connection_id, const uint8_ | |||
916 | increment_nonce(conn->sent_nonce); | 916 | increment_nonce(conn->sent_nonce); |
917 | pthread_mutex_unlock(&conn->mutex); | 917 | pthread_mutex_unlock(&conn->mutex); |
918 | 918 | ||
919 | return send_packet_to(c, crypt_connection_id, packet, sizeof(packet)); | 919 | return send_packet_to(c, crypt_connection_id, packet, SIZEOF_VLA(packet)); |
920 | } | 920 | } |
921 | 921 | ||
922 | /* Creates and sends a data packet with buffer_start and num to the peer using the fastest route. | 922 | /* Creates and sends a data packet with buffer_start and num to the peer using the fastest route. |
@@ -934,13 +934,13 @@ static int send_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uint3 | |||
934 | num = htonl(num); | 934 | num = htonl(num); |
935 | buffer_start = htonl(buffer_start); | 935 | buffer_start = htonl(buffer_start); |
936 | uint16_t padding_length = (MAX_CRYPTO_DATA_SIZE - length) % CRYPTO_MAX_PADDING; | 936 | uint16_t padding_length = (MAX_CRYPTO_DATA_SIZE - length) % CRYPTO_MAX_PADDING; |
937 | uint8_t packet[sizeof(uint32_t) + sizeof(uint32_t) + padding_length + length]; | 937 | VLA(uint8_t, packet, sizeof(uint32_t) + sizeof(uint32_t) + padding_length + length); |
938 | memcpy(packet, &buffer_start, sizeof(uint32_t)); | 938 | memcpy(packet, &buffer_start, sizeof(uint32_t)); |
939 | memcpy(packet + sizeof(uint32_t), &num, sizeof(uint32_t)); | 939 | memcpy(packet + sizeof(uint32_t), &num, sizeof(uint32_t)); |
940 | memset(packet + (sizeof(uint32_t) * 2), PACKET_ID_PADDING, padding_length); | 940 | memset(packet + (sizeof(uint32_t) * 2), PACKET_ID_PADDING, padding_length); |
941 | memcpy(packet + (sizeof(uint32_t) * 2) + padding_length, data, length); | 941 | memcpy(packet + (sizeof(uint32_t) * 2) + padding_length, data, length); |
942 | 942 | ||
943 | return send_data_packet(c, crypt_connection_id, packet, sizeof(packet)); | 943 | return send_data_packet(c, crypt_connection_id, packet, SIZEOF_VLA(packet)); |
944 | } | 944 | } |
945 | 945 | ||
946 | static int reset_max_speed_reached(Net_Crypto *c, int crypt_connection_id) | 946 | static int reset_max_speed_reached(Net_Crypto *c, int crypt_connection_id) |