Skip to content

Commit

Permalink
Make a copy of the multiaddr slice in Addrs()
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed Oct 17, 2024
1 parent ec8ebaa commit bb8de5a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion p2p/host/basic/basic_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,12 @@ func (h *BasicHost) ConnManager() connmgr.ConnManager {
// When used with AutoRelay, and if the host is not publicly reachable,
// this will only have host's private, relay, and no public addresses.
func (h *BasicHost) Addrs() []ma.Multiaddr {
addrs := h.AddrsFactory(h.AllAddrs())
// Make a copy. Consumers can modify the slice elements
res := make([]ma.Multiaddr, len(addrs))
copy(res, addrs)
// Add certhashes for the addresses provided by the user via address factory.
return h.addCertHashes(ma.Unique(h.AddrsFactory(h.AllAddrs())))
return h.addCertHashes(ma.Unique(res))
}

// NormalizeMultiaddr returns a multiaddr suitable for equality checks.
Expand Down

0 comments on commit bb8de5a

Please sign in to comment.