mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
fix(routing): defensive clone of AddrInfo from provider channel (#11120)
Some checks failed
CodeQL / codeql (push) Has been cancelled
Docker Check / lint (push) Has been cancelled
Docker Check / build (push) Has been cancelled
Gateway Conformance / gateway-conformance (push) Has been cancelled
Gateway Conformance / gateway-conformance-libp2p-experiment (push) Has been cancelled
Go Build / go-build (push) Has been cancelled
Go Check / go-check (push) Has been cancelled
Go Lint / go-lint (push) Has been cancelled
Go Test / unit-tests (push) Has been cancelled
Go Test / cli-tests (push) Has been cancelled
Go Test / example-tests (push) Has been cancelled
Interop / interop-prep (push) Has been cancelled
Sharness / sharness-test (push) Has been cancelled
Spell Check / spellcheck (push) Has been cancelled
Interop / helia-interop (push) Has been cancelled
Interop / ipfs-webui (push) Has been cancelled
Some checks failed
CodeQL / codeql (push) Has been cancelled
Docker Check / lint (push) Has been cancelled
Docker Check / build (push) Has been cancelled
Gateway Conformance / gateway-conformance (push) Has been cancelled
Gateway Conformance / gateway-conformance-libp2p-experiment (push) Has been cancelled
Go Build / go-build (push) Has been cancelled
Go Check / go-check (push) Has been cancelled
Go Lint / go-lint (push) Has been cancelled
Go Test / unit-tests (push) Has been cancelled
Go Test / cli-tests (push) Has been cancelled
Go Test / example-tests (push) Has been cancelled
Interop / interop-prep (push) Has been cancelled
Sharness / sharness-test (push) Has been cancelled
Spell Check / spellcheck (push) Has been cancelled
Interop / helia-interop (push) Has been cancelled
Interop / ipfs-webui (push) Has been cancelled
Belt-and-suspenders defense against data races where routing subsystem (DHT or delegated routing) may reuse backing array. Clones AddrInfo before publishing to QueryEvent to ensure isolated copy. Closes https://github.com/ipfs/kubo/issues/11116
This commit is contained in:
parent
07ea37e99f
commit
de20a78a1f
@ -2,12 +2,14 @@ package cmdutils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
cmds "github.com/ipfs/go-ipfs-cmds"
|
||||
|
||||
"github.com/ipfs/boxo/path"
|
||||
"github.com/ipfs/go-cid"
|
||||
coreiface "github.com/ipfs/kubo/core/coreiface"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -84,3 +86,13 @@ func PathOrCidPath(str string) (path.Path, error) {
|
||||
// Send back original err.
|
||||
return nil, originalErr
|
||||
}
|
||||
|
||||
// CloneAddrInfo returns a copy of the AddrInfo with a cloned Addrs slice.
|
||||
// This prevents data races if the sender reuses the backing array.
|
||||
// See: https://github.com/ipfs/kubo/issues/11116
|
||||
func CloneAddrInfo(ai peer.AddrInfo) peer.AddrInfo {
|
||||
return peer.AddrInfo{
|
||||
ID: ai.ID,
|
||||
Addrs: slices.Clone(ai.Addrs),
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/ipfs/kubo/config"
|
||||
cmdenv "github.com/ipfs/kubo/core/commands/cmdenv"
|
||||
"github.com/ipfs/kubo/core/commands/cmdutils"
|
||||
"github.com/ipfs/kubo/core/node"
|
||||
mh "github.com/multiformats/go-multihash"
|
||||
|
||||
@ -89,7 +90,7 @@ var findProvidersRoutingCmd = &cmds.Command{
|
||||
defer cancel()
|
||||
pchan := n.Routing.FindProvidersAsync(ctx, c, numProviders)
|
||||
for p := range pchan {
|
||||
np := p
|
||||
np := cmdutils.CloneAddrInfo(p)
|
||||
routing.PublishQueryEvent(ctx, &routing.QueryEvent{
|
||||
Type: routing.Provider,
|
||||
Responses: []*peer.AddrInfo{&np},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user