-
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: on Windows, LookPath sometimes improperly returns ErrDot #53536
Comments
The fix seems easy enough — if we would return That's still a (very minor) semantic change compared to prior versions of Go — in prior versions we would return the relative path instead of the absolute one — but that seems acceptable to me because the two paths still refer to exactly the same executable. @golang/windows, does that sound right? |
Change https://go.dev/cl/414054 mentions this issue: |
Should be fixed at HEAD, and in the next beta or RC. @dkess, thanks for testing early and reporting it! |
PiperOrigin-RevId: 458487259
PiperOrigin-RevId: 458487259
PiperOrigin-RevId: 458497738
PiperOrigin-RevId: 458498623
PiperOrigin-RevId: 458498623
PiperOrigin-RevId: 458498623
PiperOrigin-RevId: 458506657
… explicit one If the current directory is also listed explicitly in %PATH%, this changes the behavior of LookPath to prefer the explicit name for it (and thereby avoid ErrDot). However, in order to avoid running a different executable from what would have been run by previous Go versions, we still return the implicit path (and ErrDot) if it refers to a different file entirely. Fixes golang#53536. Updates golang#43724. Change-Id: I7ab01074e21a0e8b07a176e3bc6d3b8cf0c873cd Reviewed-on: https://go-review.googlesource.com/c/go/+/414054 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Caused by the changes in https://go.dev/cl/403274.
When using LookPath to lookup an executable which is both in the current working directory and in the PATH, it returns an ErrDot, which is improper since the chosen path is still in the PATH.
Example: consider
exec.LookPath("netsh")
. When run from a "normal" working directory (C:\Users\MyUser), this correctly returns"C:\Windows\system32\netsh.exe", nil
. But if the working directory isC:\Windows\system32
, it returns the relative path with ErrDot.This can subtly break any Go program that calls system32 executables that don't specify the full path, which is a common pattern.
An more concrete example from Google code: https://github.com/google/winops/blob/89df70d833b79d5b41af14ad1070df6ce09a5086/powershell/powershell_windows.go#L37. This would break if the current working directory is
C:\Windows\system32
(which happens to be the default working directory of an administrator cmd window).The text was updated successfully, but these errors were encountered: