core: resolve error + bounds check
- handle error on "/ipns/" - bounds-check, otherwise might cause a panic
Juan Batiz-Benet committed
Apr 20, 2015 at 01:32 UTC
c79dddd3d30ac3c030ccf60c94629e49a7c67b59
1 file changed
+10
-3
core/pathresolver.go
+10
-3
@@ -1,9 +1,11 @@
1
package core
2
3
import (
4
+ "fmt"
5
+ "strings"
6
+
7
merkledag "github.com/ipfs/go-ipfs/merkledag"
8
path "github.com/ipfs/go-ipfs/path"
6
- "strings"
9
)
10
11
// 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) {
22
if strings.HasPrefix(strpath, "/ipns/") {
23
// if it's an ipns path, try to resolve it.
24
// 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:]
32
key, err := n.Namesys.Resolve(n.Context(), ipnsPath)
33
if err != nil {
34
return nil, err