summaryrefslogtreecommitdiff
path: root/toxcore/net_crypto.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/net_crypto.c')
-rw-r--r--toxcore/net_crypto.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 1b78bf1b..8c1d74c7 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -752,12 +752,17 @@ static int send_data_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *dat
752static int send_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uint32_t buffer_start, uint32_t num, 752static int send_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uint32_t buffer_start, uint32_t num,
753 uint8_t *data, uint32_t length) 753 uint8_t *data, uint32_t length)
754{ 754{
755 if (length == 0 || length > MAX_CRYPTO_DATA_SIZE)
756 return -1;
757
755 num = htonl(num); 758 num = htonl(num);
756 buffer_start = htonl(buffer_start); 759 buffer_start = htonl(buffer_start);
757 uint8_t packet[sizeof(uint32_t) + sizeof(uint32_t) + length]; 760 uint16_t padding_length = (MAX_CRYPTO_DATA_SIZE - length) % CRYPTO_MAX_PADDING;
761 uint8_t packet[sizeof(uint32_t) + sizeof(uint32_t) + padding_length + length];
758 memcpy(packet, &buffer_start, sizeof(uint32_t)); 762 memcpy(packet, &buffer_start, sizeof(uint32_t));
759 memcpy(packet + sizeof(uint32_t), &num, sizeof(uint32_t)); 763 memcpy(packet + sizeof(uint32_t), &num, sizeof(uint32_t));
760 memcpy(packet + (sizeof(uint32_t) * 2), data, length); 764 memset(packet + (sizeof(uint32_t) * 2), 0, padding_length);
765 memcpy(packet + (sizeof(uint32_t) * 2) + padding_length, data, length);
761 766
762 return send_data_packet(c, crypt_connection_id, packet, sizeof(packet)); 767 return send_data_packet(c, crypt_connection_id, packet, sizeof(packet));
763} 768}