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

x/mobile: os.Executable() panics on iOS #22529

Closed
adambabik opened this issue Nov 1, 2017 · 5 comments

Comments

Projects
None yet
5 participants
@adambabik
Copy link

commented Nov 1, 2017

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

go version go1.9.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/adamb/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/g2/km2y9qqj4bbf329f2bt1xqc80000gn/T/go-build521592560=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

I have a function which calls os.Executable in my Go source file. I bind it with gomobile like this:
gomobile bind --target ios --tags ios -v and use the output framework in my iOS project in Xcode 9. Finally, I just call my Go function from ObjC.

What did you expect to see?

An executable path or error.

What did you see instead?

A panic:

panic: runtime error: index out of range

goroutine 17 [running, locked to thread]:
os.executable(...)
	/usr/local/Cellar/go/1.9.2/libexec/src/os/executable_darwin.go:13
os.Executable(...)
	/usr/local/Cellar/go/1.9.2/libexec/src/os/executable.go:21

@gopherbot gopherbot added this to the Unreleased milestone Nov 1, 2017

@gopherbot gopherbot added the mobile label Nov 1, 2017

@empijei

This comment has been minimized.

Copy link
Contributor

commented Nov 8, 2017

This is likely caused by this that does not check if the path is at least 1 character long.

This function expects the path to be set by runtime/os_darwin.go as commented here, but for some reasons this is currently not working or not called.

@eliasnaur

This comment has been minimized.

Copy link
Contributor

commented Mar 14, 2018

CC @minux, the author of https://golang.org/cl/16551 .

@josharian

This comment has been minimized.

Copy link
Contributor

commented Mar 14, 2018

Related is #24394, which occurs on macOS.

We should obviously gracefully handle the empty string case, but it'd be good to also get it to be non-empty when possible. :)

@empijei

This comment has been minimized.

Copy link
Contributor

commented Aug 2, 2018

I was thinking about changing the current implementation of executable() that does not check for the empty string:

func executable() (string, error) {
	ep := executablePath
	if ep[0] != '/' {
		if initCwdErr != nil {
			return ep, initCwdErr
		}

to something like:

func executable() (string, error) {
	ep := executablePath
	if len(ep) == 0 {
		return ep, errors.New("cannot find executable path")
	}
	if ep[0] != '/' {
		if initCwdErr != nil {
			return ep, initCwdErr
		}

CL here

@gopherbot

This comment has been minimized.

Copy link

commented Aug 2, 2018

Change https://golang.org/cl/127546 mentions this issue: os: add check for empty executable path on darwin

@gopherbot gopherbot closed this in faadda0 Aug 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.