diff options
| author | Bryan C. Mills <bcmills@google.com> | 2022-11-22 13:45:12 -0500 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-01-26 23:30:15 +0000 |
| commit | 8e0781e5ff0320d8a0cb04dded9aa0ff8f3849cd (patch) | |
| tree | 874fdf738174e9093215474eb43c9cb5b849db65 /src | |
| parent | 6f6276ce366f0f9cd9748d9c910310e0bc7dc8e5 (diff) | |
| download | go-8e0781e5ff0320d8a0cb04dded9aa0ff8f3849cd.tar.xz | |
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>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/dist/test.go | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go index 9ad2173daa..3182fd4e45 100644 --- a/src/cmd/dist/test.go +++ b/src/cmd/dist/test.go @@ -1077,6 +1077,9 @@ func flattenCmdline(cmdline []interface{}) (bin string, args []string) { } bin = list[0] + if !filepath.IsAbs(bin) { + panic("command is not absolute: " + bin) + } return bin, list[1:] } @@ -1300,16 +1303,24 @@ func (t *tester) registerCgoTests() { default: // Check for static linking support var staticCheck rtPreFunc - cmd := t.dirCmd("misc/cgo/test", - compilerEnvLookup("CC", defaultcc, goos, goarch), "-xc", "-o", "/dev/null", "-static", "-") - cmd.Stdin = strings.NewReader("int main() {}") - cmd.Stdout, cmd.Stderr = nil, nil // Discard output - if err := cmd.Run(); err != nil { - // Skip these tests + ccName := compilerEnvLookup("CC", defaultcc, goos, goarch) + cc, err := exec.LookPath(ccName) + if err != nil { staticCheck.pre = func(*distTest) bool { - fmt.Println("No support for static linking found (lacks libc.a?), skip cgo static linking test.") + 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.Stdout, cmd.Stderr = nil, nil // Discard output + if err := cmd.Run(); err != nil { + // Skip these tests + staticCheck.pre = func(*distTest) bool { + fmt.Println("No support for static linking found (lacks libc.a?), skip cgo static linking test.") + return false + } + } } // Static linking tests |
