From b65c3fa420798d59828d1ea2ff3a0a4661d2b28d Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 31 Jul 2024 15:35:05 +0100 Subject: [PATCH] add null check around assembly & location (#3606) * add null check around assembly & location * Add PathIsValid check * fmt --- .../DllConflictManager.cs | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/ConnectorCore/DllConflictManagement/DllConflictManager.cs b/ConnectorCore/DllConflictManagement/DllConflictManager.cs index 26f34f13c2..3921b8ee36 100644 --- a/ConnectorCore/DllConflictManagement/DllConflictManager.cs +++ b/ConnectorCore/DllConflictManagement/DllConflictManager.cs @@ -101,11 +101,29 @@ HashSet visitedAssemblies } } - private bool ShouldSkipCheckingConflictBecauseOfAssemblyLocation(Assembly loadedAssembly) + private static bool PathIsValid(string path) { + if (path.Any(x => Path.GetInvalidPathChars().Contains(x))) + { + return false; + } + return true; + } + + private bool ShouldSkipCheckingConflictBecauseOfAssemblyLocation(Assembly? loadedAssembly) + { + if (string.IsNullOrWhiteSpace(loadedAssembly?.Location)) + { + return false; + } + string location = loadedAssembly!.Location; + if (!PathIsValid(location)) + { + return false; + } foreach (var exactPath in _exactAssemblyPathsToIgnore) { - if (Path.GetDirectoryName(loadedAssembly.Location) == exactPath) + if (Path.GetDirectoryName(location) == exactPath) { return true; } @@ -113,7 +131,7 @@ private bool ShouldSkipCheckingConflictBecauseOfAssemblyLocation(Assembly loaded foreach (var pathFragment in _assemblyPathFragmentsToIgnore) { - if (loadedAssembly.Location.Contains(pathFragment)) + if (location.Contains(pathFragment)) { return true; }