Skip to content

Commit 4851182

Browse files
committed
env: ensure we don't return empty PATH vars on Windows
Ensure that we don't return empty `PATH` values on Windows when splitting. It's common that on Windows the `PATH` can be inadvertently modified such that an empty value is included, and this can lead to weird resolution of executables using the current directory. As it stands, no existing codepaths would trigger this today when invoked by Git for Windows, but let's make sure this never happens in the future by mistake!
1 parent 4c0cfb6 commit 4851182

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/shared/Core/Interop/Windows/WindowsEnvironment.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ internal WindowsEnvironment(IFileSystem fileSystem, IReadOnlyDictionary<string,
2222

2323
protected override string[] SplitPathVariable(string value)
2424
{
25-
return value.Split(';');
25+
// Ensure we don't return empty values here - callers may use this as the base
26+
// path for `Path.Combine(..)`, for which an empty value means 'current directory'.
27+
// We only ever want to use the current directory for path resolution explicitly.
28+
return value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
2629
}
2730

2831
public override void AddDirectoryToPath(string directoryPath, EnvironmentVariableTarget target)

0 commit comments

Comments
 (0)