Skip to content

go v1.17.x breaks the (os.exec) Cmd.Start() functionality on Windows #49044

Closed
@techema

Description

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

$ go version
1.17.2

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
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build
set GOENV=C:\Users\Administrator\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Administrator\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Administrator\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17.2
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\test\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp\go-build2858189327=/tmp/go-build -gno-record-gcc-switches

What did you do?

exec.Command().Start() has been broken on Windows by v1.17.

The following code runs properly with go 1.16.5:

	cmd := exec.Command("C:\\Windows\\System32\\timeout.exe"", "30")
	cmd.SysProcAttr = &syscall.SysProcAttr{NoInheritHandles: true, CreationFlags: 16/*CREATE_NEW_CONSOLE*/}
	err := cmd.Start()
	if err != nil {
		fmt.Println(err)
	}

However, it fails on 1.17.2 (and 1.17.1).

&fs.PathError{Op:"fork/exec", Path:"C:\\WINDOWS\\System32\\timeout.exe", Err:0x57}

I have traced it to the newly introduced ProcThreadAttributeList parameter to the _STARTUPINFOEXW
If I remove the _EXTENDED_STARTUPINFO_PRESENT flag before the call to CreateProcess, then the process is properly started.
I can also see that si.ProcThreadAttributeList gets initialized for max 2 attributes, but then they may or may not be set (depending on some conditions). then, the _EXTENDED_STARTUPINFO_PRESENT is used regardless if those attributes are set or not. I think that the flag should only be set if the attributes are set.
But furthermore, since I do not want the ParentProcess to be set, I even tried to initialize the list with max 1 attribute (and call the code for _PROC_THREAD_ATTRIBUTE_HANDLE_LIST); however, the execution still failed.

What did you expect to see?

No error, process properly started.

What did you see instead?

&fs.PathError{Op:"fork/exec", Path:"C:\\WINDOWS\\System32\\timeout.exe", Err:0x57} error

0x57 error code is "The parameter is invalid"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions