From c971f95c10b9ee79ab4c5aab2cff4e2cb642fb72 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 10 Sep 2013 12:47:43 -0400 Subject: [PATCH] go/build: allow $ in cgo LDFLAGS Fixes #6038. R=iant CC=golang-dev https://golang.org/cl/13649043 --- src/cmd/go/test.bash | 19 +++++++++++++++++++ src/pkg/go/build/build.go | 9 ++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/cmd/go/test.bash b/src/cmd/go/test.bash index 847a3e10a1..1a3adb8968 100755 --- a/src/cmd/go/test.bash +++ b/src/cmd/go/test.bash @@ -483,6 +483,25 @@ fi rm -rf $d unset GOPATH +TEST 'cgo handles -Wl,$ORIGIN' +d=$(TMPDIR=/var/tmp mktemp -d -t testgoXXX) +export GOPATH=$d +mkdir -p $d/src/origin +echo ' +package origin +// #cgo LDFLAGS: -Wl,-rpath -Wl,$ORIGIN +// void f(void) {} +import "C" + +func f() { C.f() } +' >$d/src/origin/origin.go +if ! ./testgo build origin; then + echo build failed + ok=false +fi +rm -rf $d +unset GOPATH + # clean up if $started; then stop; fi rm -rf testdata/bin testdata/bin1 diff --git a/src/pkg/go/build/build.go b/src/pkg/go/build/build.go index 043351a950..1b62c3da89 100644 --- a/src/pkg/go/build/build.go +++ b/src/pkg/go/build/build.go @@ -920,7 +920,7 @@ func (ctxt *Context) saveCgo(filename string, di *Package, cg *ast.CommentGroup) return fmt.Errorf("%s: invalid #cgo line: %s", filename, orig) } for _, arg := range args { - if !safeName(arg) { + if !safeCgoName(arg) { return fmt.Errorf("%s: malformed #cgo argument: %s", filename, arg) } } @@ -943,9 +943,12 @@ func (ctxt *Context) saveCgo(filename string, di *Package, cg *ast.CommentGroup) return nil } -var safeBytes = []byte("+-.,/0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz:") +// NOTE: $ is not safe for the shell, but it is allowed here because of linker options like -Wl,$ORIGIN. +// We never pass these arguments to a shell (just to programs we construct argv for), so this should be okay. +// See golang.org/issue/6038. +var safeBytes = []byte("+-.,/0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz:$") -func safeName(s string) bool { +func safeCgoName(s string) bool { if s == "" { return false } -- 2.50.0