diff options
| author | Damien Neil <dneil@google.com> | 2022-12-12 16:43:37 -0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-02-14 16:51:16 +0000 |
| commit | 95eb5abd6340b271ae728f99986eeccbc0354ab1 (patch) | |
| tree | 1d964b7dd47b4083a61eb0deabe1833c2635401e /src/path/filepath/path_test.go | |
| parent | 117fe2e08d2fb385e4febed020b834d2d8e4358a (diff) | |
| download | go-95eb5abd6340b271ae728f99986eeccbc0354ab1.tar.xz | |
path/filepath: do not Clean("a/../c:/b") into c:\b on Windows
Do not permit Clean to convert a relative path into one starting
with a drive reference. This change causes Clean to insert a .
path element at the start of a path when the original path does not
start with a volume name, and the first path element would contain
a colon.
This may introduce a spurious but harmless . path element under
some circumstances. For example, Clean("a/../b:/../c") becomes `.\c`.
This reverts CL 401595, since the change here supersedes the one
in that CL.
Thanks to RyotaK (https://twitter.com/ryotkak) for reporting this issue.
Fixes #57274
Fixes CVE-2022-41722
Change-Id: I837446285a03aa74c79d7642720e01f354c2ca17
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1675249
Reviewed-by: Roland Shoemaker <bracewell@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
TryBot-Result: Security TryBots <security-trybots@go-security-trybots.iam.gserviceaccount.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/468123
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/path/filepath/path_test.go')
| -rw-r--r-- | src/path/filepath/path_test.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go index 672d7e6261..9adf641013 100644 --- a/src/path/filepath/path_test.go +++ b/src/path/filepath/path_test.go @@ -106,6 +106,13 @@ var wincleantests = []PathTest{ {`//abc`, `\\abc`}, {`///abc`, `\\\abc`}, {`//abc//`, `\\abc\\`}, + + // Don't allow cleaning to move an element with a colon to the start of the path. + {`a/../c:`, `.\c:`}, + {`a\..\c:`, `.\c:`}, + {`a/../c:/a`, `.\c:\a`}, + {`a/../../c:`, `..\c:`}, + {`foo:bar`, `foo:bar`}, } func TestClean(t *testing.T) { @@ -174,6 +181,7 @@ var winislocaltests = []IsLocalTest{ {`C:`, false}, {`C:\a`, false}, {`..\a`, false}, + {`a/../c:`, false}, {`CONIN$`, false}, {`conin$`, false}, {`CONOUT$`, false}, |
