diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/net_crypto.c | 9 | ||||
-rw-r--r-- | toxcore/net_crypto.h | 2 |
2 files changed, 9 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 | |||
752 | static int send_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uint32_t buffer_start, uint32_t num, | 752 | static 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 | } |
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index 78e2f56b..79f5da35 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h | |||
@@ -76,6 +76,8 @@ | |||
76 | #define PACKET_ID_LOSSY_RANGE_START 192 | 76 | #define PACKET_ID_LOSSY_RANGE_START 192 |
77 | #define PACKET_ID_LOSSY_RANGE_SIZE 63 | 77 | #define PACKET_ID_LOSSY_RANGE_SIZE 63 |
78 | 78 | ||
79 | #define CRYPTO_MAX_PADDING 8 /* All packets will be padded a number of bytes based on this number. */ | ||
80 | |||
79 | typedef struct { | 81 | typedef struct { |
80 | uint64_t time; | 82 | uint64_t time; |
81 | uint16_t length; | 83 | uint16_t length; |