Open
Description
What version of Go are you using (go version
)?
$ go version go version go1.14.3 linux/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/scottclarke/.cache/go-build" GOENV="/home/scottclarke/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/scottclarke/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build189733440=/tmp/go-build -gno-record-gcc-switches"
What did you do?
package main
import (
"log"
"os"
"os/exec"
"syscall"
)
func main() {
cmd := exec.Command("hello")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Dir = "/"
cmd.Env = []string{"PATH=/bin"}
cmd.SysProcAttr = &syscall.SysProcAttr{Chroot: "/home/scottclarke/chroot"}
if err := cmd.Start(); err != nil {
log.Fatalf("%#v", err.Error())
}
cmd.Wait()
}
Where /home/scottclarke/chroot
contains a chroot which has an executable file /bin/hello
, and there is no executable hello
in the PATH of the system prior to the chroot.
What did you expect to see?
The hello
executable being run, producing the output hello world
.
What did you see instead?
The following error:
2020/06/01 11:36:32 "exec: \"hello\": executable file not found in $PATH"
This happens because the exec.Command()
function calls LookPath()
and sets the lookPathErr
if it fails, which is checked in Start()
and causes a failure. However this doesn't take into account the fact that the command will be run in a chroot.