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

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

Closed
techema opened this issue Oct 18, 2021 · 1 comment
Closed

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

techema opened this issue Oct 18, 2021 · 1 comment

Comments

@techema
Copy link

techema commented Oct 18, 2021

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"

@seankhliao
Copy link
Member

Duplicate of #48040
1.17 backport tracked in #48075

@golang golang locked and limited conversation to collaborators Oct 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants