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
3b2cc0082b
commit
517b10352f
1 changed files with 7 additions and 2 deletions
|
@ -13,8 +13,6 @@ const maxLoopCounter = 100
|
||||||
// FollowSymlink will follow an existing link and scope it to the root
|
// FollowSymlink will follow an existing link and scope it to the root
|
||||||
// path provided.
|
// path provided.
|
||||||
func FollowSymlinkInScope(link, root string) (string, error) {
|
func FollowSymlinkInScope(link, root string) (string, error) {
|
||||||
prev := "/"
|
|
||||||
|
|
||||||
root, err := filepath.Abs(root)
|
root, err := filepath.Abs(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -25,10 +23,17 @@ func FollowSymlinkInScope(link, root string) (string, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if link == root {
|
||||||
|
return root, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if !strings.HasPrefix(filepath.Dir(link), root) {
|
if !strings.HasPrefix(filepath.Dir(link), root) {
|
||||||
return "", fmt.Errorf("%s is not within %s", link, root)
|
return "", fmt.Errorf("%s is not within %s", link, root)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prev := "/"
|
||||||
|
|
||||||
for _, p := range strings.Split(link, "/") {
|
for _, p := range strings.Split(link, "/") {
|
||||||
prev = filepath.Join(prev, p)
|
prev = filepath.Join(prev, p)
|
||||||
prev = filepath.Clean(prev)
|
prev = filepath.Clean(prev)
|
||||||
|
|
Loading…
Reference in a new issue