Skip to content

DotNetSdkLocationHelper does not validate symlink target exists #201

Description

DotNetSdkLocationHelper looks for dotnet on the user's PATH. On non-Windows, it uses realpath to resolve symlinks, but does not check that the target exists.

// We will generally find the dotnet exe on the path, but on linux, it is often just a 'dotnet' symlink (possibly even to more symlinks) that we have to resolve
// to the real dotnet executable.
// This will work as often as just invoking dotnet from the command line, but we can be more confident in finding a dotnet executable by following
// https://github.com/dotnet/designs/blob/main/accepted/2021/install-location-per-architecture.md
// This can be done using the nethost library. We didn't do this previously, so I did not implement this extension.
foreach (string dir in Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator))
{
string filePath = Path.Combine(dir, exeName);
if (File.Exists(Path.Combine(dir, exeName)))
{
dotnetPath = filePath;
break;
}
}
if (dotnetPath != null)
{
dotnetPath = Path.GetDirectoryName(isWindows ? dotnetPath : realpath(dotnetPath) ?? dotnetPath);
}

This can end up passing a directory to hostfxr_resolve_sdk2 that does not represent a .NET install, resulting in no SDKs being found.

See dotnet/runtime#83469

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions