Skip to content

Fixing NullReferenceException when --Hashes and telemetry rules are enabled #531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 7, 2022

Conversation

eddynaka
Copy link
Contributor

With the single thread analysis, the argument --Hashes was translated to --insert Hashes, adding the deprecated message.
When we moved to the multithreaded analysis, without that condition we would not generate the artifacts.
Since the summary was expecting the artifacts, it was accessing the number of elements directly.

@eddynaka eddynaka changed the title Fixing NullReferenceException when --Hashes is enabled Fixing NullReferenceException when --Hashes and telemetry rules are enabled Dec 16, 2021
EndTimeUtc = invocation.EndTimeUtc,
TimeConsumed = invocation.EndTimeUtc - invocation.StartTimeUtc,
};
}
Copy link
Contributor Author

@eddynaka eddynaka Dec 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code was moved to the AnalysisSummaryExtractor in previous PRs. #ByDesign

@@ -40,7 +40,7 @@ public static AnalysisSummary ExtractAnalysisSummary(SarifLog sarifLog, AnalyzeO
ToolVersion = tool.Driver.Version,
NormalizedPath = string.Join(";", options.TargetFileSpecifiers.Select(p => System.IO.Path.GetDirectoryName(p)).Distinct()),
SymbolPath = options.SymbolsPath,
FileAnalyzed = artifacts.Count,
FileAnalyzed = artifacts?.Count ?? 0,
Copy link
Contributor Author

@eddynaka eddynaka Dec 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

artifacts?.Count ?? 0

this will prevent the exception in case the SARIF does not have artifacts.

This would happen if: you don't have the --insert hashes or --Hashes option enabled but you have the telemetry rules. #ByDesign

@@ -85,6 +85,17 @@ public override int Run(AnalyzeOptions analyzeOptions)
analyzeOptions.Kind = new List<ResultKind> { ResultKind.Fail, ResultKind.NotApplicable, ResultKind.Pass };
}

#pragma warning disable CS0618 // Type or member is obsolete
if (analyzeOptions.ComputeFileHashes)
Copy link
Contributor Author

@eddynaka eddynaka Dec 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

analyzeOptions.ComputeFileHashes

this change is needed to prevent a breaking change in the guardian tasks.
We need to support --Hashes #WontFix

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should make this change in SDK instead?
AnalyzeCommandBase has this check,
MultithreadedAnalyzeCommandBase does not,

if the change is made in Binskim then only Binskim is fixed but not SDK

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering about that.
Since we want to deprecate --hashes, i would move that logic to AnalyzeCommand and remove the reference from AnalyzeCommandBase.

With that, in the futhre, the options would not have --hashes by default and binskim itself would implement it.

@eddynaka eddynaka marked this pull request as ready for review December 16, 2021 01:20
[Option(
"binskimAppInsightsKey",
HelpText = "An ApplicationInsightsKey to which will be send data. If not available, it will read from the environment variable.")]
public string BinskimAppInsightsKey { get; set; }
Copy link
Contributor Author

@eddynaka eddynaka Dec 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BinskimAppInsightsKey

To facilitate the guardian integration, we will expose a new parameter and also be able to read the environment variable.

The reason: from azure pipelines, creating the variable it isn't passing the value correctly (the variable is always unavailable). #Closed

Copy link
Member

@michaelcfanning michaelcfanning Dec 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't accept a change that encourages users to explicitly provide sensitive data on the command-line, this is a very poor security practice, as command-lines are persisted/logged in many contexts. In general, you do not want to compromise your own project quality/security to workaround a bug in another system. If there is a problem with ADO environment variable handling, let's get that reported and see what we can do to resolve. ADO also provides other mechanism for sharing data, including ingestion data from secured network shares (that we could lock down to a build agent account, perhaps). Let's follow up with some folks with relevant expertise offline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the feedback.
i will remove the change and keep it clean to fix the issue that i faced.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and this is a very good point, thanks for making it. This isn't the kind of change that we'd want to fold into another PR, it would warrant its own issue. You can follow up with me and Ryley offline about your ADO issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just updated and sent an email with the details.
thanks for the help!

Copy link
Contributor

@marmegh marmegh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@@ -40,7 +40,7 @@ public static AnalysisSummary ExtractAnalysisSummary(SarifLog sarifLog, AnalyzeO
ToolVersion = tool.Driver.Version,
NormalizedPath = string.Join(";", options.TargetFileSpecifiers.Select(p => System.IO.Path.GetDirectoryName(p)).Distinct()),
SymbolPath = options.SymbolsPath,
FileAnalyzed = artifacts.Count,
FileAnalyzed = artifacts?.Count ?? 0,
// FileNotAnalyzed =
Copy link
Member

@michaelcfanning michaelcfanning Jan 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// FileNotAnalyzed =

can you remove this please? it isn't helpful to have it here.

please add a TODO, or just open an issue #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created a work item for that.

Copy link
Member

@michaelcfanning michaelcfanning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@eddynaka eddynaka enabled auto-merge (squash) January 7, 2022 01:26
@eddynaka eddynaka merged commit 006f96b into main Jan 7, 2022
@eddynaka eddynaka deleted the users/ednakamu/fixing-nullreference-exception branch January 7, 2022 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants