mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Blacklist System.Windows.Forms form loaded to prevent a crash (#6822)
Blacklist `System.Windows.Forms` (`WinForms`) from being loaded to prevent a crash
This commit is contained in:
@@ -108,6 +108,9 @@ namespace System.Management.Automation
|
||||
// - Value: strong name of the TPA that contains the type represented by Key.
|
||||
private readonly Dictionary<string, string> _coreClrTypeCatalog;
|
||||
private readonly Lazy<HashSet<string>> _availableDotNetAssemblyNames;
|
||||
private readonly HashSet<string> _blackListedAssemblies = new HashSet<string>(StringComparer.OrdinalIgnoreCase){
|
||||
"System.Windows.Forms"
|
||||
};
|
||||
|
||||
#if !UNIX
|
||||
private string _winDir;
|
||||
@@ -295,6 +298,13 @@ namespace System.Management.Automation
|
||||
private bool TryFindInGAC(AssemblyName assemblyName, out string assemblyFilePath)
|
||||
{
|
||||
assemblyFilePath = null;
|
||||
if (_blackListedAssemblies.Contains(assemblyName.Name))
|
||||
{
|
||||
// DotNet catches and throws a new exception with no inner exception
|
||||
// We cannot change the message DotNet returns.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Internal.InternalTestHooks.DisableGACLoading)
|
||||
{
|
||||
return false;
|
||||
|
||||
+1
@@ -1,5 +1,6 @@
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
Describe "Assembly.LoadFrom Validation Test" -Tags "CI" {
|
||||
BeforeAll {
|
||||
$ConsumerCode = @'
|
||||
@@ -0,0 +1,34 @@
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
Describe "Assembly::LoadWithPartialName Validation Test" -Tags "CI" {
|
||||
|
||||
$defaultErrorId = 'FileLoadException'
|
||||
$testcases = @(
|
||||
# verify winforms is blocked
|
||||
@{
|
||||
Name = 'system.windows.forms'
|
||||
ErrorId = $defaultErrorId
|
||||
}
|
||||
# Verify alternative casing is blocked
|
||||
@{
|
||||
Name = 'System.Windows.Forms'
|
||||
ErrorId = $defaultErrorId
|
||||
}
|
||||
)
|
||||
|
||||
# All existing cases should fail on all platforms either because it doesn't exist or
|
||||
# because the assembly is blacklisted
|
||||
It "Assembly::LoadWithPartialName should fail to load blacklisted assembly: <Name>" -TestCases $testcases {
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[string]
|
||||
$Name,
|
||||
[Parameter(Mandatory)]
|
||||
[string]
|
||||
$ErrorId
|
||||
)
|
||||
|
||||
{[System.Reflection.Assembly]::LoadWithPartialName($Name)} | Should -Throw -ErrorId $ErrorId
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user