diff options
author | irungentoo <irungentoo@gmail.com> | 2014-12-14 20:33:31 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-12-14 20:33:31 -0500 |
commit | 015a8b7d75d46234d0bbb97efbf07e7c26afcc15 (patch) | |
tree | f5e2738a6650e30f4ad5b13f1cc58bdb00aca90a /toxcore | |
parent | 6f3312c137cb86f17d1cd7ee97c9f6dd797fb2ce (diff) |
Sendback data size is always 8 bytes.
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/DHT.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 1e120746..203ffa4c 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -828,8 +828,6 @@ end: | |||
828 | return 0; | 828 | return 0; |
829 | } | 829 | } |
830 | 830 | ||
831 | #define NODES_ENCRYPTED_MESSAGE_LENGTH (crypto_box_NONCEBYTES + sizeof(uint64_t) + sizeof(Node_format) + sizeof(Node_format) + crypto_box_MACBYTES) | ||
832 | |||
833 | /* Send a getnodes request. | 831 | /* Send a getnodes request. |
834 | sendback_node is the node that it will send back the response to (set to NULL to disable this) */ | 832 | sendback_node is the node that it will send back the response to (set to NULL to disable this) */ |
835 | static int getnodes(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const uint8_t *client_id, | 833 | static int getnodes(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const uint8_t *client_id, |
@@ -896,7 +894,7 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public | |||
896 | if (id_equal(public_key, dht->self_public_key)) | 894 | if (id_equal(public_key, dht->self_public_key)) |
897 | return -1; | 895 | return -1; |
898 | 896 | ||
899 | if (length > NODES_ENCRYPTED_MESSAGE_LENGTH || length == 0) | 897 | if (length != sizeof(uint64_t)) |
900 | return -1; | 898 | return -1; |
901 | 899 | ||
902 | size_t Node_format_size = sizeof(Node_format); | 900 | size_t Node_format_size = sizeof(Node_format); |
@@ -940,36 +938,29 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public | |||
940 | 938 | ||
941 | static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet, uint16_t length) | 939 | static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet, uint16_t length) |
942 | { | 940 | { |
943 | uint32_t cmp_len = 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + CLIENT_ID_SIZE + crypto_box_MACBYTES; | 941 | if (length != (1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + CLIENT_ID_SIZE + sizeof(uint64_t) + crypto_box_MACBYTES)) |
944 | |||
945 | if (length <= cmp_len) | ||
946 | return 1; | 942 | return 1; |
947 | 943 | ||
948 | if (length > cmp_len + NODES_ENCRYPTED_MESSAGE_LENGTH) | ||
949 | return 1; | ||
950 | |||
951 | uint16_t sendback_data_length = length - cmp_len; | ||
952 | |||
953 | DHT *dht = object; | 944 | DHT *dht = object; |
954 | 945 | ||
955 | /* Check if packet is from ourself. */ | 946 | /* Check if packet is from ourself. */ |
956 | if (id_equal(packet + 1, dht->self_public_key)) | 947 | if (id_equal(packet + 1, dht->self_public_key)) |
957 | return 1; | 948 | return 1; |
958 | 949 | ||
959 | uint8_t plain[CLIENT_ID_SIZE + sendback_data_length]; | 950 | uint8_t plain[CLIENT_ID_SIZE + sizeof(uint64_t)]; |
960 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; | 951 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; |
961 | 952 | ||
962 | DHT_get_shared_key_recv(dht, shared_key, packet + 1); | 953 | DHT_get_shared_key_recv(dht, shared_key, packet + 1); |
963 | int len = decrypt_data_symmetric( shared_key, | 954 | int len = decrypt_data_symmetric( shared_key, |
964 | packet + 1 + CLIENT_ID_SIZE, | 955 | packet + 1 + CLIENT_ID_SIZE, |
965 | packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, | 956 | packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, |
966 | CLIENT_ID_SIZE + sendback_data_length + crypto_box_MACBYTES, | 957 | CLIENT_ID_SIZE + sizeof(uint64_t) + crypto_box_MACBYTES, |
967 | plain ); | 958 | plain ); |
968 | 959 | ||
969 | if (len != CLIENT_ID_SIZE + sendback_data_length) | 960 | if (len != CLIENT_ID_SIZE + sizeof(uint64_t)) |
970 | return 1; | 961 | return 1; |
971 | 962 | ||
972 | sendnodes_ipv6(dht, source, packet + 1, plain, plain + CLIENT_ID_SIZE, sendback_data_length, shared_key); | 963 | sendnodes_ipv6(dht, source, packet + 1, plain, plain + CLIENT_ID_SIZE, sizeof(uint64_t), shared_key); |
973 | 964 | ||
974 | add_to_ping(dht->ping, packet + 1, source); | 965 | add_to_ping(dht->ping, packet + 1, source); |
975 | 966 | ||