Skip to content

Commit

Permalink
Update symlink from docker upstream
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Demeester <[email protected]>
  • Loading branch information
vdemeester committed Oct 27, 2017
1 parent 0d57bc2 commit 4f90e1a
Show file tree
Hide file tree
Showing 5 changed files with 621 additions and 9 deletions.
2 changes: 1 addition & 1 deletion libcontainer/rootfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
"time"

"github.com/docker/docker/pkg/mount"
"github.com/opencontainers/runc/libcontainer/symlink"
"github.com/mrunalp/fileutils"
"github.com/opencontainers/runc/libcontainer/cgroups"
"github.com/opencontainers/runc/libcontainer/configs"
"github.com/opencontainers/runc/libcontainer/symlink"
"github.com/opencontainers/runc/libcontainer/system"
libcontainerUtils "github.com/opencontainers/runc/libcontainer/utils"
"github.com/opencontainers/selinux/go-selinux/label"
Expand Down
18 changes: 10 additions & 8 deletions libcontainer/symlink/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import (
"strings"
)

// FollowSymlinkInScope is a wrapper around evalSymlinksInScope that returns an absolute path
// FollowSymlinkInScope is a wrapper around evalSymlinksInScope that returns an
// absolute path. This function handles paths in a platform-agnostic manner.
func FollowSymlinkInScope(path, root string) (string, error) {
path, err := filepath.Abs(path)
path, err := filepath.Abs(filepath.FromSlash(path))
if err != nil {
return "", err
}
root, err = filepath.Abs(root)
root, err = filepath.Abs(filepath.FromSlash(root))
if err != nil {
return "", err
}
Expand All @@ -37,7 +38,7 @@ func FollowSymlinkInScope(path, root string) (string, error) {
//
// Example:
// If /foo/bar -> /outside,
// FollowSymlinkInScope("/foo/bar", "/foo") == "/foo/outside" instead of "/oustide"
// FollowSymlinkInScope("/foo/bar", "/foo") == "/foo/outside" instead of "/outside"
//
// IMPORTANT: it is the caller's responsibility to call evalSymlinksInScope *after* relevant symlinks
// are created and not to create subsequently, additional symlinks that could potentially make a
Expand Down Expand Up @@ -92,8 +93,8 @@ func evalSymlinksInScope(path, root string) (string, error) {
// root gets prepended and we Clean again (to remove any trailing slash
// if the first Clean gave us just "/")
cleanP := filepath.Clean(string(filepath.Separator) + b.String() + p)
if cleanP == string(filepath.Separator) {
// never Lstat "/" itself
if isDriveOrRoot(cleanP) {
// never Lstat "/" itself, or drive letters on Windows
b.Reset()
continue
}
Expand All @@ -110,7 +111,8 @@ func evalSymlinksInScope(path, root string) (string, error) {
return "", err
}
if fi.Mode()&os.ModeSymlink == 0 {
b.WriteString(p + string(filepath.Separator))
b.WriteString(p)
b.WriteRune(filepath.Separator)
continue
}

Expand All @@ -119,7 +121,7 @@ func evalSymlinksInScope(path, root string) (string, error) {
if err != nil {
return "", err
}
if filepath.IsAbs(dest) {
if isAbs(dest) {
b.Reset()
}
path = dest + string(filepath.Separator) + path
Expand Down
16 changes: 16 additions & 0 deletions libcontainer/symlink/fs_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// +build !windows

package symlink

import (
"path/filepath"
)

func isDriveOrRoot(p string) bool {
return p == string(filepath.Separator)
}

// isAbs is a platform-specific wrapper for filepath.IsAbs.
func isAbs(path string) bool {
return filepath.IsAbs(path)
}
Loading

0 comments on commit 4f90e1a

Please sign in to comment.