@@ -1079,18 +1079,19 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public
10791079 Node_format nodes_list [MAX_SENT_NODES ];
10801080 uint32_t num_nodes = get_close_nodes (dht , client_id , nodes_list , 0 , LAN_ip (ip_port .ip ) == 0 , 1 );
10811081
1082- if (num_nodes == 0 )
1083- return 0 ;
1084-
10851082 uint8_t plain [1 + Node_format_size * MAX_SENT_NODES + length ];
10861083 uint8_t encrypt [sizeof (plain ) + crypto_box_MACBYTES ];
10871084 uint8_t nonce [crypto_box_NONCEBYTES ];
10881085 new_nonce (nonce );
10891086
1090- int nodes_length = pack_nodes ( plain + 1 , Node_format_size * MAX_SENT_NODES , nodes_list , num_nodes ) ;
1087+ int nodes_length = 0 ;
10911088
1092- if (nodes_length <= 0 )
1093- return -1 ;
1089+ if (num_nodes ) {
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+ }
10941095
10951096 plain [0 ] = num_nodes ;
10961097 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
11761177 DHT * dht = object ;
11771178 uint32_t cid_size = 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + 1 + sizeof (uint64_t ) + crypto_box_MACBYTES ;
11781179
1179- if (length <= cid_size ) /* too short */
1180+ if (length < cid_size ) /* too short */
11801181 return 1 ;
11811182
11821183 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
12001201 if ((unsigned int )len != sizeof (plain ))
12011202 return 1 ;
12021203
1203- if (plain [0 ] > size_plain_nodes || plain [ 0 ] == 0 )
1204+ if (plain [0 ] > size_plain_nodes )
12041205 return 1 ;
12051206
12061207 Node_format sendback_node ;
@@ -1220,7 +1221,7 @@ static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *pa
12201221 if (num_nodes != plain [0 ])
12211222 return 1 ;
12221223
1223- if (num_nodes <= 0 )
1224+ if (num_nodes < 0 )
12241225 return 1 ;
12251226
12261227 /* store the address the *request* was sent to */
0 commit comments