Docker-DCO-1.1-Signed-off-by: Tibor Vass <teabee89@gmail.com> (github: tiborvass)
Tibor Vass authored on 2014/06/25 01:50:44... | ... |
@@ -13,8 +13,6 @@ const maxLoopCounter = 100 |
13 | 13 |
// FollowSymlink will follow an existing link and scope it to the root |
14 | 14 |
// path provided. |
15 | 15 |
func FollowSymlinkInScope(link, root string) (string, error) { |
16 |
- prev := "/" |
|
17 |
- |
|
18 | 16 |
root, err := filepath.Abs(root) |
19 | 17 |
if err != nil { |
20 | 18 |
return "", err |
... | ... |
@@ -25,10 +23,17 @@ func FollowSymlinkInScope(link, root string) (string, error) { |
25 | 25 |
return "", err |
26 | 26 |
} |
27 | 27 |
|
28 |
+ if link == root { |
|
29 |
+ return root, nil |
|
30 |
+ } |
|
31 |
+ |
|
32 |
+ |
|
28 | 33 |
if !strings.HasPrefix(filepath.Dir(link), root) { |
29 | 34 |
return "", fmt.Errorf("%s is not within %s", link, root) |
30 | 35 |
} |
31 | 36 |
|
37 |
+ prev := "/" |
|
38 |
+ |
|
32 | 39 |
for _, p := range strings.Split(link, "/") { |
33 | 40 |
prev = filepath.Join(prev, p) |
34 | 41 |
prev = filepath.Clean(prev) |