summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-12-17 14:05:35 -0500
committerirungentoo <irungentoo@gmail.com>2015-12-17 14:05:35 -0500
commit07b4b041fb673ed372f85954506a5c66076484d4 (patch)
tree2dcc8c4453570c5d2e6bfe36366b03d7e3e22815 /toxcore
parent0938ba08d9a839df4111168f3414099268d69737 (diff)
Allow 0 length sendnode.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/DHT.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 14c59a3d..7e5ff6ae 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -1079,18 +1079,19 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public
1079 Node_format nodes_list[MAX_SENT_NODES]; 1079 Node_format nodes_list[MAX_SENT_NODES];
1080 uint32_t num_nodes = get_close_nodes(dht, client_id, nodes_list, 0, LAN_ip(ip_port.ip) == 0, 1); 1080 uint32_t num_nodes = get_close_nodes(dht, client_id, nodes_list, 0, LAN_ip(ip_port.ip) == 0, 1);
1081 1081
1082 if (num_nodes == 0)
1083 return 0;
1084
1085 uint8_t plain[1 + Node_format_size * MAX_SENT_NODES + length]; 1082 uint8_t plain[1 + Node_format_size * MAX_SENT_NODES + length];
1086 uint8_t encrypt[sizeof(plain) + crypto_box_MACBYTES]; 1083 uint8_t encrypt[sizeof(plain) + crypto_box_MACBYTES];
1087 uint8_t nonce[crypto_box_NONCEBYTES]; 1084 uint8_t nonce[crypto_box_NONCEBYTES];
1088 new_nonce(nonce); 1085 new_nonce(nonce);
1089 1086
1090 int nodes_length = pack_nodes(plain + 1, Node_format_size * MAX_SENT_NODES, nodes_list, num_nodes); 1087 int nodes_length = 0;
1091 1088
1092 if (nodes_length <= 0) 1089 if (num_nodes) {
1093 return -1; 1090 nodes_length = pack_nodes(plain + 1, Node_format_size * MAX_SENT_NODES, nodes_list, num_nodes);
1091
1092 if (nodes_length <= 0)
1093 return -1;
1094 }
1094 1095
1095 plain[0] = num_nodes; 1096 plain[0] = num_nodes;
1096 memcpy(plain + 1 + nodes_length, sendback_data, length); 1097 memcpy(plain + 1 + nodes_length, sendback_data, length);
@@ -1176,7 +1177,7 @@ static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *pa
1176 DHT *dht = object; 1177 DHT *dht = object;
1177 uint32_t cid_size = 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + 1 + sizeof(uint64_t) + crypto_box_MACBYTES; 1178 uint32_t cid_size = 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + 1 + sizeof(uint64_t) + crypto_box_MACBYTES;
1178 1179
1179 if (length <= cid_size) /* too short */ 1180 if (length < cid_size) /* too short */
1180 return 1; 1181 return 1;
1181 1182
1182 uint32_t data_size = length - cid_size; 1183 uint32_t data_size = length - cid_size;
@@ -1200,7 +1201,7 @@ static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *pa
1200 if ((unsigned int)len != sizeof(plain)) 1201 if ((unsigned int)len != sizeof(plain))
1201 return 1; 1202 return 1;
1202 1203
1203 if (plain[0] > size_plain_nodes || plain[0] == 0) 1204 if (plain[0] > size_plain_nodes)
1204 return 1; 1205 return 1;
1205 1206
1206 Node_format sendback_node; 1207 Node_format sendback_node;
@@ -1220,7 +1221,7 @@ static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *pa
1220 if (num_nodes != plain[0]) 1221 if (num_nodes != plain[0])
1221 return 1; 1222 return 1;
1222 1223
1223 if (num_nodes <= 0) 1224 if (num_nodes < 0)
1224 return 1; 1225 return 1;
1225 1226
1226 /* store the address the *request* was sent to */ 1227 /* store the address the *request* was sent to */