Skip to content

Commit

Permalink
Adding type check to avoid empty IAnalysisLogger in the first plase o…
Browse files Browse the repository at this point in the history
…f context.Logger.Loggers
  • Loading branch information
AllDwarf committed Aug 7, 2024
1 parent d8bc8cd commit da3bd09
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/BinSkim.Driver/MultithreadedAnalyzeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Linq;
using System.Reflection;

using CommandLine;

using Microsoft.CodeAnalysis.BinaryParsers;
using Microsoft.CodeAnalysis.IL.Rules;
using Microsoft.CodeAnalysis.IL.Sdk;
Expand Down Expand Up @@ -52,13 +54,21 @@ public override BinaryAnalyzerContext InitializeGlobalContextFromOptions(Analyze

if (this.Telemetry?.TelemetryClient != null)
{
// Create an aggregating logger that will combine all loggers into a single logger.
var aggregatingLogger = new AggregatingLogger();
if (context.Logger is AggregatingLogger)
{
aggregatingLogger = context.Logger as AggregatingLogger;
}
else
{
aggregatingLogger.Loggers.Add(context.Logger);
}

var ruleTelemetryLogger = new RuleTelemetryLogger(this.Telemetry.TelemetryClient);
ruleTelemetryLogger.AnalysisStarted();

// Combine rule telemetry with any other loggers that may be present.
aggregatingLogger.Loggers.Add(context.Logger);
aggregatingLogger.Loggers.Add(ruleTelemetryLogger);

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning

Variable
aggregatingLogger
may be null at this access because of
this
assignment.
context.Logger = aggregatingLogger;
}
Expand Down

0 comments on commit da3bd09

Please sign in to comment.