diff options
| author | Ian Lance Taylor <iant@golang.org> | 2023-09-20 16:16:29 -0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-10-11 20:40:57 +0000 |
| commit | e7c142a19d8b3944c2f1b9ab7fd94c63d8d0c555 (patch) | |
| tree | 19136664d4352fca16cc78422ddf62e74800de7d /src/cmd/compile/internal/noder/noder.go | |
| parent | a5943e9de13b050c20aa2490082206232af4615c (diff) | |
| download | go-e7c142a19d8b3944c2f1b9ab7fd94c63d8d0c555.tar.xz | |
cmd/compile: use absolute file name in isCgo check
For #23672
Fixes #63211
Fixes CVE-2023-39323
Change-Id: I4586a69e1b2560036afec29d53e53cf25e6c7352
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/2032884
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Roland Shoemaker <bracewell@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/534158
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/cmd/compile/internal/noder/noder.go')
| -rw-r--r-- | src/cmd/compile/internal/noder/noder.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/noder/noder.go b/src/cmd/compile/internal/noder/noder.go index 4ffc3715be..1652dc6618 100644 --- a/src/cmd/compile/internal/noder/noder.go +++ b/src/cmd/compile/internal/noder/noder.go @@ -332,8 +332,14 @@ func (p *noder) pragma(pos syntax.Pos, blankLine bool, text string, old syntax.P // contain cgo directives, and for security reasons // (primarily misuse of linker flags), other files are not. // See golang.org/issue/23672. +// Note that cmd/go ignores files whose names start with underscore, +// so the only _cgo_ files we will see from cmd/go are generated by cgo. +// It's easy to bypass this check by calling the compiler directly; +// we only protect against uses by cmd/go. func isCgoGeneratedFile(pos syntax.Pos) bool { - return strings.HasPrefix(filepath.Base(trimFilename(pos.Base())), "_cgo_") + // We need the absolute file, independent of //line directives, + // so we call pos.Base().Pos(). + return strings.HasPrefix(filepath.Base(trimFilename(pos.Base().Pos().Base())), "_cgo_") } // safeArg reports whether arg is a "safe" command-line argument, |
