@@ -842,7 +842,7 @@ int net_send_packet(const Networking_Core *net, const IP_Port *ip_port, Packet p
842842{
843843 IP_Port ipp_copy = * ip_port ;
844844
845- if (net_family_is_unspec (ip_port -> ip .family )) {
845+ if (net_family_is_unspec (ipp_copy . ip .family )) {
846846 // TODO(iphydf): Make this an error. Currently this fails sometimes when
847847 // called from DHT.c:do_ping_and_sendnode_requests.
848848 return -1 ;
@@ -905,7 +905,7 @@ int net_send_packet(const Networking_Core *net, const IP_Port *ip_port, Packet p
905905 }
906906
907907 const long res = net_sendto (net -> ns , net -> sock , packet .data , packet .length , & addr , & ipp_copy );
908- net_log_data (net -> log , "O=>" , packet .data , packet .length , ip_port , res );
908+ net_log_data (net -> log , "O=>" , packet .data , packet .length , & ipp_copy , res );
909909
910910 assert (res <= INT_MAX );
911911
@@ -934,7 +934,8 @@ int sendpacket(const Networking_Core *net, const IP_Port *ip_port, const uint8_t
934934 */
935935static int receivepacket (const Network * _Nonnull ns , const Logger * _Nonnull log , Socket sock , IP_Port * _Nonnull ip_port , uint8_t * _Nonnull data , uint32_t * _Nonnull length )
936936{
937- memset (ip_port , 0 , sizeof (IP_Port ));
937+ ipport_reset (ip_port );
938+
938939 Network_Addr addr = {{0 }};
939940 addr .size = sizeof (addr .addr );
940941 * length = 0 ;
@@ -1431,13 +1432,25 @@ void ip_reset(IP *ip)
14311432static const IP_Port empty_ip_port = {{{0 }}};
14321433
14331434/** nulls out ip_port */
1434- void ipport_reset (IP_Port * ipport )
1435+ void ipport_reset (IP_Port * _Nonnull ipport )
14351436{
14361437 if (ipport == nullptr ) {
14371438 return ;
14381439 }
14391440
1441+ #ifdef RANDOM_PADDING
1442+ // Leave padding bytes as uninitialized data. This should not matter, because we
1443+ // then set all the actual fields to 0.
1444+ IP_Port empty ;
1445+ empty .ip .family .value = 0 ;
1446+ empty .ip .ip .v6 .uint64 [0 ] = 0 ;
1447+ empty .ip .ip .v6 .uint64 [1 ] = 0 ;
1448+ empty .port = 0 ;
1449+
1450+ * ipport = empty ;
1451+ #else
14401452 * ipport = empty_ip_port ;
1453+ #endif /* RANDOM_PADDING */
14411454}
14421455
14431456/** nulls out ip, sets family according to flag */
@@ -1546,7 +1559,7 @@ bool bin_pack_ip_port(Bin_Pack *bp, const Logger *logger, const IP_Port *ip_port
15461559 Ip_Ntoa ip_str ;
15471560 // TODO(iphydf): Find out why we're trying to pack invalid IPs, stop
15481561 // doing that, and turn this into an error.
1549- LOGGER_TRACE (logger , "cannot pack invalid IP: %s" , net_ip_ntoa (& ip_port -> ip , & ip_str ));
1562+ LOGGER_DEBUG (logger , "cannot pack invalid IP: %s" , net_ip_ntoa (& ip_port -> ip , & ip_str ));
15501563 return false;
15511564 }
15521565
@@ -1566,6 +1579,7 @@ int pack_ip_port(const Logger *logger, uint8_t *data, uint16_t length, const IP_
15661579 const uint32_t size = bin_pack_obj_size (bin_pack_ip_port_handler , ip_port , logger );
15671580
15681581 if (size > length ) {
1582+ LOGGER_ERROR (logger , "not enough space for packed IP: %u but need %u" , length , size );
15691583 return -1 ;
15701584 }
15711585
0 commit comments