Skip to content

Commit

Permalink
CA-382850: Catch exception when listing pipe names with invalid chara…
Browse files Browse the repository at this point in the history
…cters

Pipes can be created with invalid characters in their names (such as `|`). This results in an exception being thrown when those files are accessed via standard API calls such as `Directory.GetFiles`. Other processes might create these pipes and inadvertently prevent XenCenter from starting altogether.

Signed-off-by: Danilo Del Busso <[email protected]>
  • Loading branch information
danilo-delbusso committed Sep 12, 2023
1 parent 139186d commit 099e220
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion XenCenterLib/NamedPipes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,38 @@ public Pipe(string path)
public static bool ExistsPipe(string pipePath)
{
log.Debug($"Checking {pipePath} exists");
return Directory.GetFiles(@"\\.\pipe\").Contains(pipePath);

// CA-382850: We iterate manually in order to catch ArgumentExceptions
// when listing files. Pipes can be created with invalid characters in
// their names. This throws exception when those files are accessed.
// Other processes might create these pipes and inadvertently prevent
// XenCenter from starting

var e = Directory.EnumerateFiles(@"\\.\pipe\");
using (var enumerator = e.GetEnumerator())
{
while (true)
{
try
{
if (!enumerator.MoveNext())
{
break;
}

if (enumerator.Current != null && enumerator.Current.Contains(pipePath))
{
return true;
}
}
catch (ArgumentException)
{
// ignore, the pipe's name contains invalid characters
}
}
}

return false;
}

/// <summary>
Expand Down

0 comments on commit 099e220

Please sign in to comment.