Skip to content

Commit 40e437e

Browse files
committed
Fix empty-address panic in known_peers()
Skip peers with empty addresses in known_peers() instead of panicking, preventing a DoS via poisoned peer contacts with no advertised addresses.
1 parent 6457c32 commit 40e437e

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

network-libp2p/src/discovery/peer_contacts.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -512,20 +512,12 @@ impl PeerContactBook {
512512
pub fn known_peers(&self) -> Vec<(PeerId, PeerInfo)> {
513513
self.peer_contacts
514514
.iter()
515-
.map(|(peer_id, contact)| {
516-
(
515+
.filter_map(|(peer_id, contact)| {
516+
let address = contact.contact.inner.addresses.first()?.clone();
517+
Some((
517518
*peer_id,
518-
PeerInfo::new(
519-
contact
520-
.contact
521-
.inner
522-
.addresses
523-
.first()
524-
.expect("every peer should have at least one address")
525-
.clone(),
526-
contact.contact.inner.services,
527-
),
528-
)
519+
PeerInfo::new(address, contact.contact.inner.services),
520+
))
529521
})
530522
.collect()
531523
}

0 commit comments

Comments
 (0)