-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
os/exec: modifications to Path ignored when *Cmd is created using Command with an absolute path on Windows #68314
Comments
Change https://go.dev/cl/596875 mentions this issue: |
It seems that as long as we determine the cachedLookextensions and cmd.Path has a common no extension path prefix determines whether to use cachedLookExtension, which can solve the issue. |
For example:C:\go.exe and C:\gofmt, no extension path is C:\go and C:\gofmt ,it no equel, so don't use cachedLookExtension. |
If the no extension path is the same and the extension is different, my solution will fail. |
@gopherbot Please backport to Go 1.22. Only Go 1.22 needs the fix, as this isn't an issue in Go 1.21. This is a regression that can cause wrong binaries to be executed on Windows, with no workaround other than changing user code. |
Backport issue(s) opened: #68331 (for 1.22). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases. |
Change https://go.dev/cl/596976 mentions this issue: |
….Path is unmodified Caching the invocation of lookExtensions on an absolute path in Command and reusing the cached result in Start is only viable if Cmd.Path isn't set to a different value after Command returns. For #66586. For #68314. Fixes #68331. Change-Id: I57007850aca2011b11344180c00faded737617b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/596875 Reviewed-by: qiu laidongfeng2 <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> (cherry picked from commit d0146bd) Reviewed-on: https://go-review.googlesource.com/c/go/+/596976
This can be reproduced at tip, go1.23rc1, and go1.22.5 on Windows (but not other OSes).
go1.22.4 and go1.21.12 are unaffected.
What did you do?
Create an
*exec.Cmd
usingexec.Command
, giving it an absolute path.Modify its
Path
field (and, optionally,Args[0]
) to point to another command.Run it.
What did you see happen?
The modified value of
Cmd.Path
is ignored. The command that's actually invoked is from the originalCommand
call.What did you expect to see?
The command whose path is specified in
Cmd.Path
is the one that's executed.Here's a small reproducer. For brevity, it uses the go and gofmt binaries.
CC @golang/windows, @ianlancetaylor.
The text was updated successfully, but these errors were encountered: