mirror of
https://github.com/golang/go
synced 2024-11-23 16:40:03 -07:00
cmd/dist: require absolute path to executable in flattenCommandLine
This should help to prevent bugs from unintended use of system tools, especially the system or bootstrap "go" command. (Suggested by Austin on CL 452678.) Updates #31567. Change-Id: I71809ee30d06eda4b5ff8f90656d4f1a462d35dd Reviewed-on: https://go-review.googlesource.com/c/go/+/452776 Reviewed-by: Austin Clements <austin@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
6f6276ce36
commit
8e0781e5ff
15
src/cmd/dist/test.go
vendored
15
src/cmd/dist/test.go
vendored
@ -1077,6 +1077,9 @@ func flattenCmdline(cmdline []interface{}) (bin string, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bin = list[0]
|
bin = list[0]
|
||||||
|
if !filepath.IsAbs(bin) {
|
||||||
|
panic("command is not absolute: " + bin)
|
||||||
|
}
|
||||||
return bin, list[1:]
|
return bin, list[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1300,8 +1303,15 @@ func (t *tester) registerCgoTests() {
|
|||||||
default:
|
default:
|
||||||
// Check for static linking support
|
// Check for static linking support
|
||||||
var staticCheck rtPreFunc
|
var staticCheck rtPreFunc
|
||||||
cmd := t.dirCmd("misc/cgo/test",
|
ccName := compilerEnvLookup("CC", defaultcc, goos, goarch)
|
||||||
compilerEnvLookup("CC", defaultcc, goos, goarch), "-xc", "-o", "/dev/null", "-static", "-")
|
cc, err := exec.LookPath(ccName)
|
||||||
|
if err != nil {
|
||||||
|
staticCheck.pre = func(*distTest) bool {
|
||||||
|
fmt.Printf("$CC (%q) not found, skip cgo static linking test.\n", ccName)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cmd := t.dirCmd("misc/cgo/test", cc, "-xc", "-o", "/dev/null", "-static", "-")
|
||||||
cmd.Stdin = strings.NewReader("int main() {}")
|
cmd.Stdin = strings.NewReader("int main() {}")
|
||||||
cmd.Stdout, cmd.Stderr = nil, nil // Discard output
|
cmd.Stdout, cmd.Stderr = nil, nil // Discard output
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
@ -1311,6 +1321,7 @@ func (t *tester) registerCgoTests() {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Static linking tests
|
// Static linking tests
|
||||||
if goos != "android" && p != "netbsd/arm" {
|
if goos != "android" && p != "netbsd/arm" {
|
||||||
|
Loading…
Reference in New Issue
Block a user