mirror of
https://github.com/golang/go.git
synced 2026-04-03 09:49:56 +09:00
cmd/go: reject an empty tool name
An empty tool name ("") is incorrectly resolved by "go tool" as the directory
containing the tools binaries:
$ go tool ""
go tool : fork/exec /opt/homebrew/Cellar/go/1.24.5/libexec/pkg/tool/darwin_arm64: permission denied
To fix that case we also explicitely disallow an empty tool name in the
cmd/go/internal/base.ValidToolName func.
Tests: go test cmd/go -v '-run=Script/^tool_name$'
Fixes #74757.
Change-Id: I6dd14096526c9113cef8e4d16a5aaa2120410b08
Reviewed-on: https://go-review.googlesource.com/c/go/+/690435
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
committed by
Michael Matloob
parent
59bafc0b07
commit
86b5e678e8
@@ -42,6 +42,9 @@ func ToolPath(toolName string) (string, error) {
|
||||
}
|
||||
|
||||
func ValidToolName(toolName string) bool {
|
||||
if toolName == "" {
|
||||
return false
|
||||
}
|
||||
for _, c := range toolName {
|
||||
switch {
|
||||
case 'a' <= c && c <= 'z', '0' <= c && c <= '9', c == '_':
|
||||
|
||||
22
src/cmd/go/testdata/script/tool_name.txt
vendored
Normal file
22
src/cmd/go/testdata/script/tool_name.txt
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
[short] skip 'runs go build'
|
||||
|
||||
# Tool name can't be empty. Issue #74757.
|
||||
! go tool ''
|
||||
stderr 'go: no such tool ""'
|
||||
|
||||
! go tool -n ''
|
||||
stderr 'go: no such tool ""'
|
||||
|
||||
# Invalid tool name
|
||||
! go tool @
|
||||
stderr 'go: no such tool "@"'
|
||||
|
||||
! go tool -n @
|
||||
stderr 'go: no such tool "@"'
|
||||
|
||||
-- go.mod --
|
||||
module example.com/foo
|
||||
|
||||
go 1.24
|
||||
-- main.go --
|
||||
package main
|
||||
Reference in New Issue
Block a user