cmd/go/internal/base: reject an empty tool name
An empty tool name ("") is incorrectly resolved 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
validToolName func.
Fixes #74757.
diff --git a/src/cmd/go/internal/base/tool.go b/src/cmd/go/internal/base/tool.go
index f2fc0ff..dc35ca2 100644
--- a/src/cmd/go/internal/base/tool.go
+++ b/src/cmd/go/internal/base/tool.go
@@ -42,6 +42,9 @@
}
func ValidToolName(toolName string) bool {
+ if toolName == "" {
+ return false
+ }
for _, c := range toolName {
switch {
case 'a' <= c && c <= 'z', '0' <= c && c <= '9', c == '_':
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
this should have a test as well
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Olivier Menguéthis should have a test as well
Acknowledged
New tests added for "go tool":
```
go test cmd/go -v -run=Script/^tool_name$
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
# Tool name can't be empty. Issue #74757.It's probably OK to create a new testscript file if needed, but it might be better to see if these checks fit in an existing file. I didn't look too hard, but for example, the existing tool_exename.txt has some checks like:
```
# Don't use v2 as the short name of the tool.
! go tool v2
stderr 'go: no such tool "v2"'
```
So you could consider instead adding your new tests to the end of the existing checks in tool_exename.txt for example, or looking to see if there is a better fit in another file.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Tests moved to tool_exename.txt as suggested.
It's probably OK to create a new testscript file if needed, but it might be better to see if these checks fit in an existing file. I didn't look too hard, but for example, the existing tool_exename.txt has some checks like:
```
# Don't use v2 as the short name of the tool.
! go tool v2
stderr 'go: no such tool "v2"'
```So you could consider instead adding your new tests to the end of the existing checks in tool_exename.txt for example, or looking to see if there is a better fit in another file.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
# 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 "@"'
We're not checking for the name of the produced executable in these testcases. Perhaps we should put these cases in a different file?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
# 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 "@"'
We're not checking for the name of the produced executable in these testcases. Perhaps we should put these cases in a different file?
In "tool_exename.txt", "exename" refers to the name of the tool to execute. Any suggestion for a better name for the test file?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
# 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 "@"'
Olivier MenguéWe're not checking for the name of the produced executable in these testcases. Perhaps we should put these cases in a different file?
In "tool_exename.txt", "exename" refers to the name of the tool to execute. Any suggestion for a better name for the test file?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Test script moved to tool_name.txt as proposed by Michael.
# 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 "@"'
Olivier MenguéWe're not checking for the name of the produced executable in these testcases. Perhaps we should put these cases in a different file?
Michael MatloobIn "tool_exename.txt", "exename" refers to the name of the tool to execute. Any suggestion for a better name for the test file?
tool_name?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +2 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |