From 0544bc2baf8aa17a416ebe5dd877588c4fab8ccb Mon Sep 17 00:00:00 2001 From: Mike Richmond Date: Tue, 9 Aug 2016 10:04:29 -0700 Subject: [PATCH 1/2] Fixing load of ALC.dll so it is only included in the TPA list once for side-by-side scenarios. --- .../nativemsh/pwrshcommon/pwrshcommon.cpp | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/powershell-native/nativemsh/pwrshcommon/pwrshcommon.cpp b/src/powershell-native/nativemsh/pwrshcommon/pwrshcommon.cpp index 41457cb236..35f8286e87 100644 --- a/src/powershell-native/nativemsh/pwrshcommon/pwrshcommon.cpp +++ b/src/powershell-native/nativemsh/pwrshcommon/pwrshcommon.cpp @@ -1355,14 +1355,27 @@ namespace NativeMsh LPCSTR vals[nMaxProps]; int nProps = 0; - // If I do not include my managed enload point dll in this list, I get a security error. + // The TPA list is the required list of CoreCLR assemblies that comprise + // the trusted platform upon which PowerShell will run. std::stringstream assemblyList; bool listEmpty = true; this->GetTrustedAssemblyList(hostEnvironment.GetCoreCLRDirectoryPath(), assemblyList, listEmpty); - char coreCLRPowerShellExtInstallPath[MAX_PATH]; - ::ExpandEnvironmentStringsA(coreCLRPowerShellExtInstallDirectory, coreCLRPowerShellExtInstallPath, MAX_PATH); - this->GetTrustedAssemblyList(coreCLRPowerShellExtInstallPath, assemblyList, listEmpty); + // Fall back to attempt to load the CLR from the inbox location if + // the configuration file pointed to an invalid directory. + if (listEmpty) + { + char coreCLRPowerShellExtInstallPath[MAX_PATH]; + ::ExpandEnvironmentStringsA(coreCLRPowerShellExtInstallDirectory, coreCLRPowerShellExtInstallPath, MAX_PATH); + this->GetTrustedAssemblyList(coreCLRPowerShellExtInstallPath, assemblyList, listEmpty); + } + if (listEmpty) + { + // No CoreCLR assemblies were found in either location. There is no + // point in continuing. + this->output->DisplayMessage(false, g_STARTING_CLR_FAILED, GetLastError()); + return EXIT_CODE_INIT_FAILURE; + } props[nProps] = "TRUSTED_PLATFORM_ASSEMBLIES"; std::string tempStr = assemblyList.str(); From 6f8794d83561b7615878100672e6e0fa13c81f71 Mon Sep 17 00:00:00 2001 From: Mike Richmond Date: Tue, 9 Aug 2016 13:23:11 -0700 Subject: [PATCH 2/2] Correcting the fix to work with inbox PS --- .../nativemsh/pwrshcommon/pwrshcommon.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/powershell-native/nativemsh/pwrshcommon/pwrshcommon.cpp b/src/powershell-native/nativemsh/pwrshcommon/pwrshcommon.cpp index 35f8286e87..85250cd4c0 100644 --- a/src/powershell-native/nativemsh/pwrshcommon/pwrshcommon.cpp +++ b/src/powershell-native/nativemsh/pwrshcommon/pwrshcommon.cpp @@ -1361,9 +1361,11 @@ namespace NativeMsh bool listEmpty = true; this->GetTrustedAssemblyList(hostEnvironment.GetCoreCLRDirectoryPath(), assemblyList, listEmpty); - // Fall back to attempt to load the CLR from the inbox location if - // the configuration file pointed to an invalid directory. - if (listEmpty) + // Fall back to attempt to load the CLR from the alternate inbox location + // or if the ALC was not located in the CoreCLR directory. + std::string assemblyListToSearch = assemblyList.str(); + if (listEmpty || + (std::string::npos == assemblyListToSearch.rfind("Microsoft.PowerShell.CoreCLR.AssemblyLoadContext"))) { char coreCLRPowerShellExtInstallPath[MAX_PATH]; ::ExpandEnvironmentStringsA(coreCLRPowerShellExtInstallDirectory, coreCLRPowerShellExtInstallPath, MAX_PATH);