Skip to content

Process.Start resolves non-executable paths on Unix #129736

Closed

Description

@tmds

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:

// 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.

// 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;
}

cc @omajid @nicrowe00

@adamsitnik ptal.

Activity

  1. added
    untriaged
    on Jun 23, 2026
  2. dotnet-policy-service commented on Jun 23, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-io
    See info in area-owners.md if you want to be subscribed.

  3. dotnet-policy-service commented on Jun 23, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-diagnostics-process
    See info in area-owners.md if you want to be subscribed.

  4. removed
    untriaged
    on Jul 2, 2026
  5. added this to the 11.0.0 milestone on Jul 2, 2026
  6. adamsitnik commented on Jul 2, 2026

    @adamsitnik
    Member

    @tmds thanks for another great bug report!

    We should unify the checks, both in the managed and native parts:

    // Make sure we can find and access the executable. exec will do this, of course, but at that point it's already
    // in the child process, at which point it'll translate to the child process' exit code rather than to failing
    // the Start itself. There's a race condition here, in that this could change prior to exec's checks, but there's
    // little we can do about that. There are also more rigorous checks exec does, such as validating the executable
    // format of the target; such errors will emerge via the child process' exit code.
    if (access(filename, X_OK) != 0)

    @tmds Would you like to provide a fix?

  7. locked and limited conversation to collaborators on Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions