Commit f6ff806e authored by Baokun Lee's avatar Baokun Lee Committed by Bryan C. Mills

cmd/go: refuse -w with an invalid GOPATH

Fixes #35338

Change-Id: Ic2a3a446ef56b1e5723d6192c8aeec32ae0bbeac
Reviewed-on: https://go-review.googlesource.com/c/go/+/205779
Run-TryBot: Baokun Lee <nototon@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBryan C. Mills <bcmills@google.com>
parent e6c12c3d
......@@ -353,6 +353,13 @@ func checkEnvWrite(key, val string) error {
default:
return fmt.Errorf("invalid %s value %q", key, val)
}
case "GOPATH":
if strings.HasPrefix(val, "~") {
return fmt.Errorf("GOPATH entry cannot start with shell metacharacter '~': %q", val)
}
if !filepath.IsAbs(val) && val != "" {
return fmt.Errorf("GOPATH entry is relative; must be absolute path: %q", val)
}
}
if !utf8.ValidString(val) {
......
......@@ -89,3 +89,10 @@ stderr 'arguments must be KEY=VALUE: invalid argument: GOOS'
# go env -w rejects invalid GO111MODULE values, as otherwise cmd/go would break
! go env -w GO111MODULE=badvalue
stderr 'invalid GO111MODULE value "badvalue"'
# go env -w rejects invalid GOPATH values
! go env -w GOPATH=~/go
stderr 'GOPATH entry cannot start with shell metacharacter'
! go env -w GOPATH=./go
stderr 'GOPATH entry is relative; must be absolute path'
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment