Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: ${SRCDIR} does not handle paths with % #16959

Closed
aronatkins opened this issue Sep 1, 2016 · 6 comments

Comments

@aronatkins
Copy link

commented Sep 1, 2016

What version of Go are you using (go version)?

go version go1.6.3 linux/amd64
Also tested with go version go1.6.3 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

What did you do?

mkdir a%2fb
cd a%2fb
mkdir include

Save this Go program as a%2fb/silly.go:

package main

// #cgo CFLAGS: -I"${SRCDIR}/include"
import "C"

func main() {
}

What did you expect to see?

Expected successful compilation/execution of the program.

What did you see instead?

# go run silly.go
package main: /somewhere/a%2Fb/silly.go: malformed #cgo argument: -I/somewhere/a%2Fb/include

This happens for CFLAGS and LDFLAGS on multiple architectures.

Related to #7906, #16455, #11868, which all discuss spaces in paths; there are issues with other valid path characters as well.

This path was not something I created naturally; it was a side-effect of our CI environment (Jenkins) which occasionally uses paths like foo%2Fbar if a Git branch has a name "foo/bar". It also can create paths like foo%2Fbar@2 when a second scratch directory is needed.

@aronatkins

This comment has been minimized.

Copy link
Author

commented Sep 1, 2016

I am able to use bind mounts as a workaround. Something like:

mkdir /simplename
mount -o bind $PWD /simplename
cd /simplename
<go commands that previously failed...>
@quentinmit

This comment has been minimized.

Copy link
Contributor

commented Sep 6, 2016

Have you tried "-I${SRCDIR}/include" (that is, put quotes around the entire argument?)

@quentinmit quentinmit added this to the Go1.8Maybe milestone Sep 6, 2016

@aronatkins

This comment has been minimized.

Copy link
Author

commented Sep 6, 2016

Behavior is the same with full argument quoting.

@aronatkins

This comment has been minimized.

Copy link
Author

commented Sep 6, 2016

Note: I tried full argument quoting for CFLAGS with -I but did not re-test LDFLAGS.

@quentinmit quentinmit added the NeedsFix label Oct 10, 2016

@rsc

This comment has been minimized.

Copy link
Contributor

commented Oct 20, 2016

The list of allowed characters for $SRCDIR is src/go/build/build.go's safeString. % is not one of them.
I am a bit wary of adding % for fear that it will lead to environment variable interpolation on Windows,
but I guess we can try it.

@rsc rsc self-assigned this Oct 20, 2016

@gopherbot

This comment has been minimized.

Copy link

commented Oct 20, 2016

CL https://golang.org/cl/31611 mentions this issue.

@gopherbot gopherbot closed this in 157ce90 Oct 24, 2016

@golang golang locked and limited conversation to collaborators Oct 24, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants
You can’t perform that action at this time.