]> Cypherpunks repositories - gostls13.git/commitdiff
path/filepath: correct symlink eval for symlink at root
authorIan Lance Taylor <iant@golang.org>
Thu, 13 Sep 2018 19:18:09 +0000 (12:18 -0700)
committerIan Lance Taylor <iant@golang.org>
Thu, 13 Sep 2018 21:34:56 +0000 (21:34 +0000)
For a relative symlink in the root directory, such as /tmp ->
private/tmp, we were dropping the leading slash.

No test because we can't create a symlink in the root directory.
The test TestGZIPFilesHaveZeroMTimes was failing on the Darwin builders.

Updates #19922
Updates #20506

Change-Id: Ic83cb6d97ad0cb628fc551ac772a44fb3e20f038
Reviewed-on: https://go-review.googlesource.com/135295
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/path/filepath/symlink.go

index 57dcbf314d12564cf03a01f582309d0105fff939..98a92357bedb2b5d306128d9695b0eda5457c6b3 100644 (file)
@@ -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]