Skip to content

Commit c79dddd

Browse files
committed
core: resolve error + bounds check
- handle error on "/ipns/" - bounds-check, otherwise might cause a panic
1 parent 928581c commit c79dddd

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

core/pathresolver.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package core
22

33
import (
4+
"fmt"
5+
"strings"
6+
47
merkledag "github.com/ipfs/go-ipfs/merkledag"
58
path "github.com/ipfs/go-ipfs/path"
6-
"strings"
79
)
810

911
// Resolves the given path by parsing out /ipns/ entries and then going
@@ -20,8 +22,13 @@ func Resolve(n *IpfsNode, p path.Path) (*merkledag.Node, error) {
2022
if strings.HasPrefix(strpath, "/ipns/") {
2123
// if it's an ipns path, try to resolve it.
2224
// if we can't, we can give that error back to the user.
23-
ipnsPath := p.Segments()[1]
24-
extensions := p.Segments()[2:]
25+
seg := p.Segments()
26+
if len(seg) < 2 || seg[1] == "" { // just "/ipns/"
27+
return nil, fmt.Errorf("invalid path: %s", string(p))
28+
}
29+
30+
ipnsPath := seg[1]
31+
extensions := seg[2:]
2532
key, err := n.Namesys.Resolve(n.Context(), ipnsPath)
2633
if err != nil {
2734
return nil, err

0 commit comments

Comments
 (0)