Skip to content

Commit

Permalink
swarm/fuse: do not support relative path for fuse mounting (ethereum#629
Browse files Browse the repository at this point in the history
)

* do not support relative paths for fuse
  • Loading branch information
acud authored May 26, 2018
1 parent f9811d2 commit e3a63d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 6 additions & 1 deletion cmd/swarm/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"context"
"fmt"
"path/filepath"
"strings"
"time"

Expand All @@ -45,7 +46,11 @@ func mount(cliContext *cli.Context) {
defer cancel()

mf := &fuse.MountInfo{}
err = client.CallContext(ctx, mf, "swarmfs_mount", args[0], args[1])
mountPoint, err := filepath.Abs(filepath.Clean(args[1]))
if err != nil {
utils.Fatalf("error expanding path for mount point: %v", err)
}
err = client.CallContext(ctx, mf, "swarmfs_mount", args[0], mountPoint)
if err != nil {
utils.Fatalf("had an error calling the RPC endpoint while mounting: %v", err)
}
Expand Down
14 changes: 9 additions & 5 deletions swarm/fuse/swarmfs_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ import (
)

var (
errEmptyMountPoint = errors.New("need non-empty mount point")
errMaxMountCount = errors.New("max FUSE mount count reached")
errMountTimeout = errors.New("mount timeout")
errAlreadyMounted = errors.New("mount point is already serving")
errEmptyMountPoint = errors.New("need non-empty mount point")
errNoRelativeMountPoint = errors.New("invalid path for mount point (need absolute path)")
errMaxMountCount = errors.New("max FUSE mount count reached")
errMountTimeout = errors.New("mount timeout")
errAlreadyMounted = errors.New("mount point is already serving")
)

func isFUSEUnsupportedError(err error) bool {
Expand All @@ -48,7 +49,7 @@ func isFUSEUnsupportedError(err error) bool {
return err == fuse.ErrOSXFUSENotFound
}

// information about every active mount
// MountInfo contains information about every active mount
type MountInfo struct {
MountPoint string
StartManifest string
Expand Down Expand Up @@ -78,6 +79,9 @@ func (swarmfs *SwarmFS) Mount(mhash, mountpoint string) (*MountInfo, error) {
if mountpoint == "" {
return nil, errEmptyMountPoint
}
if !strings.HasPrefix(mountpoint, "/") {
return nil, errNoRelativeMountPoint
}
cleanedMountPoint, err := filepath.Abs(filepath.Clean(mountpoint))
if err != nil {
return nil, err
Expand Down

0 comments on commit e3a63d1

Please sign in to comment.