aboutsummaryrefslogtreecommitdiff
path: root/src/path/filepath
diff options
context:
space:
mode:
Diffstat (limited to 'src/path/filepath')
-rw-r--r--src/path/filepath/symlink.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/path/filepath/symlink.go b/src/path/filepath/symlink.go
index 57dcbf314d..98a92357be 100644
--- a/src/path/filepath/symlink.go
+++ b/src/path/filepath/symlink.go
@@ -41,14 +41,15 @@ func walkSymlinks(path string) (string, error) {
continue
} else if path[start:end] == ".." {
// Back up to previous component if possible.
+ // Note that volLen includes any leading slash.
var r int
- for r = len(dest) - 1; r >= 0; r-- {
+ for r = len(dest) - 1; r >= volLen; r-- {
if os.IsPathSeparator(dest[r]) {
break
}
}
- if r < 0 {
- if len(dest) > 0 {
+ if r < volLen {
+ if len(dest) > volLen {
dest += string(os.PathSeparator)
}
dest += ".."
@@ -117,12 +118,12 @@ func walkSymlinks(path string) (string, error) {
// Symlink to relative path; replace last
// path component in dest.
var r int
- for r = len(dest) - 1; r >= 0; r-- {
+ for r = len(dest) - 1; r >= volLen; r-- {
if os.IsPathSeparator(dest[r]) {
break
}
}
- if r < 0 {
+ if r < volLen {
dest = vol
} else {
dest = dest[:r]