From dff049c2ecd693fb6ab70f319a570c1bdf2f83d7 Mon Sep 17 00:00:00 2001 From: GarmashAlex Date: Thu, 13 Mar 2025 22:44:07 +0300 Subject: [PATCH] p2p: return copy of capabilities in Peer.Caps() --- p2p/peer.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/p2p/peer.go b/p2p/peer.go index a01df63d0c..3689635162 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -173,8 +173,10 @@ func (p *Peer) Fullname() string { // Caps returns the capabilities (supported subprotocols) of the remote peer. func (p *Peer) Caps() []Cap { - // TODO: maybe return copy - return p.rw.caps + // Return a copy of the capabilities slice to prevent modification of the original + caps := make([]Cap, len(p.rw.caps)) + copy(caps, p.rw.caps) + return caps } // RunningCap returns true if the peer is actively connected using any of the