Skip to content

os/exec: on Windows, LookPath sometimes improperly returns ErrDot #53536

Closed
@dkess

Description

@dkess

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 is C:\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).

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions