Skip to content

net5.0/net6.0/netstandard builds pick a non-executable file earlier on the overlay PATH, so the command fails with "Permission denied" instead of running the executable copy later on #139

Open

Description

@matt-edmondson

What's wrong

TryExecutable (RunCommand/RunCommand.cs, around line 510) skips files with no execute bit. That check sits inside #if NET7_0_OR_GREATER, because it uses File.GetUnixFileMode. The net5.0, net6.0, netstandard2.0 and netstandard2.1 builds therefore accept any file that exists.

On Linux and macOS those builds can pick a non-executable file over a real executable later on the overlay PATH. Neither the README ("On other platforms the file must have an execute bit") nor the method's XML doc mentions this limit.

ExecuteAsyncShouldSkipANonExecutableFileOnTheOverlayPath passes only because the test project targets net10.0, so it never exercises those builds. The behaviour came in with #137.

Repro (Linux)

The repro is a net6.0 console app that references the library's net6.0 build. The #if is decided at compile time, so the runtime version doesn't matter.

/tmp/rc-noexec/rctool   mode 644, prints "non-executable copy"
/tmp/rc-exec/rctool     mode 755, prints "executable copy"
var opts = new CommandOptions { EnvironmentVariables = new Dictionary<string, string?> { ["PATH"] = "/tmp/rc-noexec:/tmp/rc-exec:/usr/bin:/bin" } };
await RunCommand.ExecuteAsync("rctool", [], new LineOutputHandler(Console.WriteLine, Console.WriteLine), opts, CancellationToken.None);
  • Observed: Win32Exception: An error occurred trying to start process '/tmp/rc-noexec/rctool' ... Permission denied
  • Expected: executable copy, which is what PATH=/tmp/rc-noexec:/tmp/rc-exec sh -c rctool prints.

Suggested fix

  • Builds below net7: on non-Windows platforms, check with libc access(path, X_OK) through P/Invoke. Also consider doing this on net7+. The current "any execute bit" test accepts a 0700 file owned by another user, which the caller can't run, so a shell would skip it and RunCommand doesn't.
  • Tests: run the overlay-PATH tests against a pre-net7 target too, or add a unit test of TryExecutable that is compiled for those TFMs.

Activity

  1. matt-edmondson commented on Nov 4, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions