-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix `BA2027.EnableSourceLink` unexpectedly cause `ExceptionLoadingPdb` error when the PDB file is missing. * Fix release notes --------- Co-authored-by: Michael C. Fanning <[email protected]>
- Loading branch information
1 parent
e030fce
commit c135a49
Showing
16 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
using FluentAssertions; | ||
|
||
using Xunit; | ||
|
||
namespace Microsoft.CodeAnalysis.IL.Rules | ||
{ | ||
public class RulePropertyTests | ||
{ | ||
private static readonly string[] ExpectedLogPdbLoadExceptionRules = new string[] | ||
{ | ||
"BA2002.DoNotIncorporateVulnerableDependencies", | ||
"BA2006.BuildWithSecureTools", | ||
"BA2007.EnableCriticalCompilerWarnings", | ||
"BA2011.EnableStackProtection", | ||
"BA2013.InitializeStackProtection", | ||
"BA2014.DoNotDisableStackProtectionForFunctions", | ||
"BA2024.EnableSpectreMitigations", | ||
"BA2025.EnableShadowStack", | ||
"BA2026.EnableMicrosoftCompilerSdlSwitch", | ||
"BA6001.DisableIncrementalLinkingInReleaseBuilds", | ||
"BA6002.EliminateDuplicateStrings", | ||
"BA6004.EnableComdatFolding", | ||
"BA6005.EnableOptimizeReferences", | ||
"BA6006.EnableLinkTimeCodeGeneration" | ||
}; | ||
|
||
[Fact] | ||
public void RulePropertyTests_LogPdbLoadException() | ||
{ | ||
WindowsBinaryAndPdbSkimmerBase[] skimmers = | ||
GetAllWindowsBinaryAndPdbSkimmers("BinSkim.Rules.dll"); | ||
IEnumerable<WindowsBinaryAndPdbSkimmerBase> actualLogPdbLoadExceptionRules = | ||
skimmers.Where(s => s.LogPdbLoadException); | ||
IEnumerable<WindowsBinaryAndPdbSkimmerBase> unexpectedLogPdbLoadExceptionRules = | ||
actualLogPdbLoadExceptionRules.Where(s => !ExpectedLogPdbLoadExceptionRules.Contains(s.Moniker)); | ||
|
||
if (unexpectedLogPdbLoadExceptionRules.Any()) | ||
{ | ||
Assert.Fail(string.Format("Please examine if the following rules should enable 'LogPdbLoadException': {0}", | ||
string.Join(", ", unexpectedLogPdbLoadExceptionRules.Select(skimmer => skimmer.Moniker)))); | ||
} | ||
} | ||
|
||
private static WindowsBinaryAndPdbSkimmerBase[] GetAllWindowsBinaryAndPdbSkimmers(string rulesAssemblyName) | ||
{ | ||
string directory = AppDomain.CurrentDomain.BaseDirectory; | ||
string assemblyPath = Path.Combine(directory, rulesAssemblyName); | ||
var assembly = Assembly.LoadFrom(assemblyPath); | ||
Type[] assemblyTypes = assembly.GetTypes(); | ||
IEnumerable<Type> inheritanceTypes = | ||
assemblyTypes.Where(t => t.BaseType == typeof(WindowsBinaryAndPdbSkimmerBase)); | ||
IEnumerable<WindowsBinaryAndPdbSkimmerBase> instances = | ||
inheritanceTypes.Select(t => (WindowsBinaryAndPdbSkimmerBase)Activator.CreateInstance(t)); | ||
return instances.ToArray(); | ||
} | ||
} | ||
} |
Binary file added
BIN
+12 KB
...st.UnitTests.BinaryParsers/TestData/PE/Determinism/E_OUTOFMEMORY/CPlusPlus_SourceLink.exe
Binary file not shown.
File renamed without changes.
Binary file removed
BIN
-5.5 KB
...Parsers/TestData/PE/Determinism/E_OUTOFMEMORY/Managed_x64_VS2022_CSharp_Net70_Default.dll
Binary file not shown.
Binary file added
BIN
+12 KB
...est.UnitTests.BinaryParsers/TestData/PE/Determinism/E_PDB_FORMAT/CPlusPlus_SourceLink.exe
Binary file not shown.
File renamed without changes.
Binary file removed
BIN
-5.5 KB
...yParsers/TestData/PE/Determinism/E_PDB_FORMAT/Managed_x64_VS2022_CSharp_Net70_Default.dll
Binary file not shown.
Binary file added
BIN
+12 KB
....UnitTests.BinaryParsers/TestData/PE/Determinism/E_PDB_NOT_FOUND/CPlusPlus_SourceLink.exe
Binary file not shown.
Binary file removed
BIN
-5.5 KB
...rsers/TestData/PE/Determinism/E_PDB_NOT_FOUND/Managed_x64_VS2022_CSharp_Net70_Default.dll
Binary file not shown.
Binary file added
BIN
+12 KB
src/Test.UnitTests.BinaryParsers/TestData/PE/Determinism/OK/CPlusPlus_SourceLink.exe
Binary file not shown.
Binary file added
BIN
+716 KB
src/Test.UnitTests.BinaryParsers/TestData/PE/Determinism/OK/CPlusPlus_SourceLink.pdb
Binary file not shown.
Binary file removed
BIN
-5.5 KB
...ests.BinaryParsers/TestData/PE/Determinism/OK/Managed_x64_VS2022_CSharp_Net70_Default.dll
Binary file not shown.
Binary file removed
BIN
-10.3 KB
...ests.BinaryParsers/TestData/PE/Determinism/OK/Managed_x64_VS2022_CSharp_Net70_Default.pdb
Binary file not shown.