Skip to content

Commit

Permalink
commands/swarm(fix): handle empty multiaddrs
Browse files Browse the repository at this point in the history
These are technically valid at the moment so they aren't caught when calling
`NewMultiaddr`. See multiformats/go-multiaddr#104.

fixes #6354
  • Loading branch information
Stebalien committed May 20, 2019
1 parent 3c000c4 commit 83d7405
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/commands/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,17 @@ func resolveAddresses(ctx context.Context, addrs []string) ([]ma.Multiaddr, erro

maddrC := make(chan ma.Multiaddr)

for _, addr := range addrs {
for i, addr := range addrs {
maddr, err := ma.NewMultiaddr(addr)
if err != nil {
return nil, err
}

// only way to check for "empty" multiaddrs at the moment.
if len(maddr.Bytes()) == 0 {
return nil, fmt.Errorf("multiaddr %d is empty", i)
}

// check whether address ends in `ipfs/Qm...`
if _, last := ma.SplitLast(maddr); last.Protocol().Code == ma.P_IPFS {
maddrs = append(maddrs, maddr)
Expand Down

0 comments on commit 83d7405

Please sign in to comment.