fix bug in FollowSymlinkInScope when link == root
Docker-DCO-1.1-Signed-off-by: Tibor Vass <teabee89@gmail.com> (github: tiborvass)
This commit is contained in:
parent
01d4fd76dd
commit
385c9b1a08
2 changed files with 8 additions and 3 deletions
|
@ -945,4 +945,4 @@ func TestModeHostname(t *testing.T) {
|
|||
deleteAllContainers()
|
||||
|
||||
logDone("run - hostname and several network modes")
|
||||
}
|
||||
}
|
|
@ -13,8 +13,6 @@ const maxLoopCounter = 100
|
|||
// FollowSymlink will follow an existing link and scope it to the root
|
||||
// path provided.
|
||||
func FollowSymlinkInScope(link, root string) (string, error) {
|
||||
prev := "/"
|
||||
|
||||
root, err := filepath.Abs(root)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -25,10 +23,17 @@ func FollowSymlinkInScope(link, root string) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
if link == root {
|
||||
return root, nil
|
||||
}
|
||||
|
||||
|
||||
if !strings.HasPrefix(filepath.Dir(link), root) {
|
||||
return "", fmt.Errorf("%s is not within %s", link, root)
|
||||
}
|
||||
|
||||
prev := "/"
|
||||
|
||||
for _, p := range strings.Split(link, "/") {
|
||||
prev = filepath.Join(prev, p)
|
||||
prev = filepath.Clean(prev)
|
||||
|
|
Loading…
Reference in a new issue