Repository navigation
Closed
Milestone
Description
The following program fails to launch uname a second time due to the uname file that was created in the working directory:
if (File.Exists("uname")) File.Delete("uname");
Process.Start("uname").WaitForExit();
File.WriteAllText("uname", "");
Process.Start("uname").WaitForExit();When we try to find the path to execute on PATH we check if the file is an executable:
runtime/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessUtils.cs
Lines 31 to 33 in 5a0f44b
| // On Unix, we need to verify the file has execute permissions. | |
| // On Windows, any file that exists is considered executable. | |
| if (IsExecutable(path)) |
The executable check isn't performed when trying to probe the executable directory and the current directory.
runtime/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessUtils.Unix.cs
Lines 347 to 367 in 5a0f44b
| // Then check the executable's directory | |
| string? path = Environment.ProcessPath; | |
| if (path != null) | |
| { | |
| try | |
| { | |
| path = Path.Combine(Path.GetDirectoryName(path)!, filename); | |
| if (File.Exists(path)) | |
| { | |
| return path; | |
| } | |
| } | |
| catch (ArgumentException) { } // ignore any errors in data that may come from the exe path | |
| } | |
| // Then check the current directory | |
| path = Path.Combine(Directory.GetCurrentDirectory(), filename); | |
| if (File.Exists(path)) | |
| { | |
| return path; | |
| } |
@adamsitnik ptal.
Reacted by Omair Majid
Activity
dotnet-policy-service commentedon Jun 23, 2026
Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Jun 23, 2026
Tagging subscribers to this area: @dotnet/area-system-diagnostics-process
See info in area-owners.md if you want to be subscribed.
adamsitnik commentedon Jul 2, 2026
@tmds thanks for another great bug report!
We should unify the checks, both in the managed and native parts:
runtime/src/native/libs/System.Native/pal_process.c
Lines 577 to 582 in ad0692a
@tmds Would you like to provide a fix?
Process.Unix: skip non-executable files during process filename resol…
Process.Unix: skip non-executable files during process filename resol…