From 4a03752b1ff6f8866e10ba973efec7e00e15c246 Mon Sep 17 00:00:00 2001 From: Eddy Nakamura Date: Fri, 15 Oct 2021 17:03:35 -0300 Subject: [PATCH] Do not return 1 when DoNotBreak is enabled for PDB loading issues (#506) * Do not return 1 when DoNotBreak is enabled for PDB loading issues * Updating options * Addressing PR feedback --- src/BinSkim.Driver/AnalyzeCommand.cs | 1 + src/BinSkim.Driver/AnalyzeOptions.cs | 5 +++++ .../PERules/WindowsBinaryAndPdbSkimmerBase.cs | 7 ++++++- src/BinSkim.Sdk/BinaryAnalyzerContext.cs | 2 ++ .../BaselineTests.cs | 11 +---------- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/BinSkim.Driver/AnalyzeCommand.cs b/src/BinSkim.Driver/AnalyzeCommand.cs index 8b869c295..37fa3cd43 100644 --- a/src/BinSkim.Driver/AnalyzeCommand.cs +++ b/src/BinSkim.Driver/AnalyzeCommand.cs @@ -32,6 +32,7 @@ protected override BinaryAnalyzerContext CreateContext(AnalyzeOptions options, I BinaryAnalyzerContext binaryAnalyzerContext = base.CreateContext(options, logger, runtimeErrors, policy, filePath); binaryAnalyzerContext.SymbolPath = options.SymbolsPath; + binaryAnalyzerContext.IgnorePdbLoadError = options.IgnorePdbLoadError; binaryAnalyzerContext.TracePdbLoads = options.Traces.Contains(nameof(Traces.PdbLoad)); binaryAnalyzerContext.LocalSymbolDirectories = options.LocalSymbolDirectories; diff --git a/src/BinSkim.Driver/AnalyzeOptions.cs b/src/BinSkim.Driver/AnalyzeOptions.cs index 5c03d194a..bc5445a38 100644 --- a/src/BinSkim.Driver/AnalyzeOptions.cs +++ b/src/BinSkim.Driver/AnalyzeOptions.cs @@ -43,5 +43,10 @@ public class AnalyzeOptions : AnalyzeOptionsBase HelpText = "Emit verbose output. The resulting comprehensive report is designed to provide appropriate evidence for compliance scenarios.")] [Obsolete("Use --level and --kind instead.")] public bool Verbose { get; set; } + + [Option( + "ignorePdbLoadError", + HelpText = "If enabled, BinSkim won't break if we have a 'PdbLoadingException'.")] + public bool IgnorePdbLoadError { get; set; } } } diff --git a/src/BinSkim.Rules/PERules/WindowsBinaryAndPdbSkimmerBase.cs b/src/BinSkim.Rules/PERules/WindowsBinaryAndPdbSkimmerBase.cs index c71a10073..2ce74d4be 100644 --- a/src/BinSkim.Rules/PERules/WindowsBinaryAndPdbSkimmerBase.cs +++ b/src/BinSkim.Rules/PERules/WindowsBinaryAndPdbSkimmerBase.cs @@ -155,7 +155,12 @@ public static void LogExceptionLoadingPdb(IAnalysisContext context, PdbException pdbException.ExceptionDisplayMessage)); s_PdbExceptions.TryAdd(key, true); - context.RuntimeErrors |= RuntimeConditions.ExceptionLoadingPdb; + + // We should only log if doNotBreak is false + if (context is BinaryAnalyzerContext binaryAnalyzerContext && !binaryAnalyzerContext.IgnorePdbLoadError) + { + context.RuntimeErrors |= RuntimeConditions.ExceptionLoadingPdb; + } if (!string.IsNullOrEmpty(pdbException.LoadTrace)) { diff --git a/src/BinSkim.Sdk/BinaryAnalyzerContext.cs b/src/BinSkim.Sdk/BinaryAnalyzerContext.cs index bd5d911a3..f67941112 100644 --- a/src/BinSkim.Sdk/BinaryAnalyzerContext.cs +++ b/src/BinSkim.Sdk/BinaryAnalyzerContext.cs @@ -79,6 +79,8 @@ public string MimeType public CompilerDataLogger CompilerDataLogger { get; set; } + public bool IgnorePdbLoadError { get; set; } + private bool disposed = false; protected virtual void Dispose(bool disposing) diff --git a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTests.cs b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTests.cs index f73a54921..2ed690546 100644 --- a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTests.cs +++ b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTests.cs @@ -104,6 +104,7 @@ private void RunRules(StringBuilder sb, string inputFileName) Recurse = false, PrettyPrint = true, DataToInsert = new[] { OptionallyEmittedData.Hashes }, + DataToRemove = new[] { OptionallyEmittedData.NondeterministicProperties }, OutputFilePath = actualFileName, ConfigurationFilePath = "default", SarifOutputVersion = Sarif.SarifVersion.Current, @@ -139,16 +140,6 @@ private void RunRules(StringBuilder sb, string inputFileName) actualText = Regex.Replace(actualText, @"\s*""fullName""[^\n]+?\n", Environment.NewLine); actualText = Regex.Replace(actualText, @"\s*""semanticVersion""[^\n]+?\n", Environment.NewLine); - actualText = Regex.Replace(actualText, @"\s*""sarifLoggerVersion""[^\n]+?\n", Environment.NewLine); - actualText = Regex.Replace(actualText, @"\s*""dottedQuadFileVersion""[^\n]+?\n", Environment.NewLine); - actualText = Regex.Replace(actualText, @"\s*""Comments""[^\n]+?\n", Environment.NewLine); - actualText = Regex.Replace(actualText, @"\s*""CompanyName""[^\n]+?\n", Environment.NewLine); - actualText = Regex.Replace(actualText, @"\s*""ProductName""[^\n]+?\n", Environment.NewLine); - - actualText = Regex.Replace(actualText, @"\s*""time""[^\n]+?\n", Environment.NewLine); - actualText = Regex.Replace(actualText, @"\s*""endTimeUtc""[^\n]+?\n", Environment.NewLine); - actualText = Regex.Replace(actualText, @"\s*""startTimeUtc""[^\n]+?\n", Environment.NewLine); - actualText = Regex.Replace(actualText, @"\s*""processId""[^\n]+?\n", Environment.NewLine); actualText = Regex.Replace(actualText, @" ""id""[^,]+,\s+""tool""", @" ""tool""", RegexOptions.Multiline); // Write back the normalized actual text so that the diff command given on failure shows what was actually compared.