-
Notifications
You must be signed in to change notification settings - Fork 18k
os/exec: unexpected ErrDot returned if there is an empty path in PATH #61493
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
Comments
Note that an empty path is meaningful on Unix systems, and means the current directory. So at least on Unix systems the behavior sounds correct. I don't know what an empty path means on Windows systems. |
cc @golang/windows |
empty path also means the current directory in Windows. However, the logic to deal with the current directory logic shouldn't be handled in |
The check at line 103, for the |
But I could be wrong, and would be happy to see a pointer to some Windows docs explaining how empty strings should be handled in |
I'm not aware of any Microsoft-vetted rule that says how to handle empty Doing a quick search, I saw that Rust skips empty entries (source), so they are never used to evaluate potential executable locations. IMO, standard lacking, our behavior is also good and consistent. If someone has added an empty entry, then we should honor it and return the binary at the working directory and |
Of course, we should honor that someone adds an empty entry. But we should also think that running an application as a service in Windows will make the working directory in the Unlike Unix, we can decide where is the working directory. Windows is set (or maybe I don't know how to change it.) |
@LawyZheng, |
Hmm, I think I see what you are saying. If there is an explicit empty entry in |
Perhaps, updating |
In my previous comment I said that Rust was skipping empty entries. Well, I found out that PowerShell's Get-Command also skips empty entries. This behavior is not documented, but I've reproduced it locally and also found the code that does the skipping: https://github.com/PowerShell/PowerShell/blob/18350bc9ff28532d3d75cf4f07642d35fd8c490b/src/System.Management.Automation/engine/CommandDiscovery.cs#L1216 I'm starting to think that honoring |
Can we get an update on this? Experiencing issues with this behaviour where empty/NIL PATH entries on Windows OS are resolving to relative path, making it impossible to use |
Change https://go.dev/cl/528037 mentions this issue: |
Change https://go.dev/cl/548481 mentions this issue: |
For #61422. Updates #62596. Updates #61493. Change-Id: I5c910f9961da24d90b3618ee53540118db06ff91 Reviewed-on: https://go-review.googlesource.com/c/go/+/548481 Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Alex Brainman <[email protected]> Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
For golang#61422. Updates golang#62596. Updates golang#61493. Change-Id: I5c910f9961da24d90b3618ee53540118db06ff91 Reviewed-on: https://go-review.googlesource.com/c/go/+/548481 Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Alex Brainman <[email protected]> Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
no tested yet
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
As an apology, although my build env is
Mac M1
, I cross-compiled the application into theamd64 windows
.So this is a description of the Windows system.
I missed to set my PATH with a empty path, like
path1;;path2;
So when I wanted to use
exec.Command
to open thecmd.exe
(my working directory isC:/Windows/System32
, just the same ascmd.exe
lies), I got aErrDot
.In this situation, I got 2 ways to find the
cmd.exe
in PATH. The one is to find in the absolute pathC:/Windows/System32
, and the other one is the empty path which I entered by mistake. And the empty one comes first.go/src/os/exec/lp_windows.go
Lines 103 to 139 in 8abc6e2
In line 114, it enters the empty path which is considered as the
.
path, and findscmd.exe
in this path.Without a doubt, it is treated as a
RELATIVE PATH
and returned with an ErrDot.I know the relative path is forbidden now.
And I think this is similar to the problem mentioned in the #53536, but not exactly the same.
What did you expect to see?
I have to admit that this is my fault to set an empty path by mistake.
But I still wonder whether the logic in this code should be optimized or not.
Provided with my two opinions as below:
In the PATH list, skip the empty path or anything like the relative path which will function as the
.
path eventually. After all, there is no need to deal with the.
path in this code, because it has been dealt with before.We can sort the list before range it. Make the absolute paths come before the relative paths.
The text was updated successfully, but these errors were encountered: