aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/cgo_path.txt
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2021-01-22 14:27:24 -0500
committerDmitri Shuralyov <dmitshur@golang.org>2021-02-02 17:58:14 +0000
commit4a48a7d7bda25a844a7e597e96041b55c9f32d4d (patch)
treea69566e02e40ed681cd2b2f73dfa6b2bf708c46d /src/cmd/go/testdata/script/cgo_path.txt
parenta01db0df00fed281f6a9673eb93fe6acae6197cf (diff)
downloadgo-4a48a7d7bda25a844a7e597e96041b55c9f32d4d.tar.gz
go-4a48a7d7bda25a844a7e597e96041b55c9f32d4d.zip
[release-branch.go1.15] cmd/go: don't lookup the path for CC when invoking cgo
Previously, if CC was a path without separators (like gcc or clang), we'd look it up in PATH in cmd/go using internal/execabs.LookPath, then pass the resolved path to cgo in CC. This caused a regression: if the directory in PATH containing CC has a space, cgo splits it and interprets it as multiple arguments. With this change, cmd/go no longer resolves CC before invoking cgo. cgo does the path lookup on each invocation. This reverts the security fix CL 284780, but that was redundant with the addition of internal/execabs (CL 955304), which still protects us. NOTE: This CL includes a related test fix from CL 286292. Fixes #43860 Change-Id: I65d91a1e303856df8653881eb6e2e75a3bf95c49 Reviewed-on: https://go-review.googlesource.com/c/go/+/285873 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> (cherry picked from commit a2cef9b544708ecae983ed8836ee2425a28aab68) Reviewed-on: https://go-review.googlesource.com/c/go/+/285954 Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Diffstat (limited to 'src/cmd/go/testdata/script/cgo_path.txt')
-rw-r--r--src/cmd/go/testdata/script/cgo_path.txt12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/cmd/go/testdata/script/cgo_path.txt b/src/cmd/go/testdata/script/cgo_path.txt
index 0d15998426..3eba71bc15 100644
--- a/src/cmd/go/testdata/script/cgo_path.txt
+++ b/src/cmd/go/testdata/script/cgo_path.txt
@@ -1,12 +1,20 @@
[!cgo] skip
+# Set CC explicitly to something that requires a PATH lookup.
+# Normally, the default is gcc or clang, but if CC was set during make.bash,
+# that becomes the default.
+[exec:clang] env CC=clang
+[exec:gcc] env CC=gcc
+[!exec:clang] [!exec:gcc] skip 'Unknown C compiler'
+
env GOCACHE=$WORK/gocache # Looking for compile flags, so need a clean cache.
[!windows] env PATH=.:$PATH
-[!windows] chmod 0777 p/gcc p/clang
+[!windows] chmod 0755 p/gcc p/clang
[!windows] exists -exec p/gcc p/clang
[windows] exists -exec p/gcc.bat p/clang.bat
! exists p/bug.txt
-go build -x
+! go build -x
+stderr '^cgo: exec (clang|gcc): (clang|gcc) resolves to executable in current directory \(.[/\\](clang|gcc)(.bat)?\)$'
! exists p/bug.txt
-- go.mod --