Skip to content

Commit

Permalink
Do not return 1 when DoNotBreak is enabled for PDB loading issues (#506)
Browse files Browse the repository at this point in the history
* Do not return 1 when DoNotBreak is enabled for PDB loading issues

* Updating options

* Addressing PR feedback
  • Loading branch information
eddynaka authored Oct 15, 2021
1 parent 8a14aa9 commit 4a03752
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/BinSkim.Driver/AnalyzeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions src/BinSkim.Driver/AnalyzeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
7 changes: 6 additions & 1 deletion src/BinSkim.Rules/PERules/WindowsBinaryAndPdbSkimmerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
2 changes: 2 additions & 0 deletions src/BinSkim.Sdk/BinaryAnalyzerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 1 addition & 10 deletions src/Test.FunctionalTests.BinSkim.Driver/BaselineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 4a03752

Please sign in to comment.