Skip to content
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

Fix null cfg bug. #3050

Merged
merged 2 commits into from Nov 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -77,6 +77,11 @@ public override void Initialize(AnalysisContext context)
}

ControlFlowGraph cfg = operationBlockStartContext.OperationBlocks.GetControlFlowGraph();
if (cfg == null)
Copy link
Member

Choose a reason for hiding this comment

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

Can we create a unit test for this?

Copy link
Contributor

@dotpaul dotpaul Nov 18, 2019

Choose a reason for hiding this comment

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

Looks like Test_NullCfg_NoDiagnostic covers this.

Any performance concerns with GetControlFlowGraph() off the top of your head?

Copy link
Member

Choose a reason for hiding this comment

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

Oh are we creating a CFG for every operation block? We should certainly avoid that. CFG should only be computed for methods where we know will be perfoming DFA.

Copy link
Member

Choose a reason for hiding this comment

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

@dotpaul Can we create a work item/PR to ensure we create CFG lazily at the point where we know we will be executing DFA?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was hoping @LLLXXXCCC could fix this instance in this PR. I think this is the only place where the CFG is can be created without attempting DFA.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll fix a new PR.

{
return;
}

WellKnownTypeProvider wellKnownTypeProvider = WellKnownTypeProvider.GetOrCreate(compilation);
InterproceduralAnalysisConfiguration interproceduralAnalysisConfiguration = InterproceduralAnalysisConfiguration.Create(
options,
Expand Down Expand Up @@ -115,12 +120,11 @@ public override void Initialize(AnalysisContext context)
operationAnalysisContext =>
{
IPropertyReferenceOperation propertyReferenceOperation = (IPropertyReferenceOperation)operationAnalysisContext.Operation;
IOperation rootOperation = operationAnalysisContext.Operation.GetRoot();
if (sourceInfoSymbolMap.IsSourceProperty(propertyReferenceOperation.Property))
{
lock (rootOperationsNeedingAnalysis)
{
rootOperationsNeedingAnalysis.Add(rootOperation);
rootOperationsNeedingAnalysis.Add(propertyReferenceOperation.GetRoot());
}
}
},
Expand All @@ -130,20 +134,16 @@ public override void Initialize(AnalysisContext context)
operationAnalysisContext =>
{
IInvocationOperation invocationOperation = (IInvocationOperation)operationAnalysisContext.Operation;
IOperation rootOperation = operationAnalysisContext.Operation.GetRoot();
if (rootOperation.TryGetEnclosingControlFlowGraph(out ControlFlowGraph cfg))
if (sourceInfoSymbolMap.IsSourceMethod(
invocationOperation.TargetMethod,
invocationOperation.Arguments,
pointsToFactory,
valueContentFactory,
out _))
{
if (sourceInfoSymbolMap.IsSourceMethod(
invocationOperation.TargetMethod,
invocationOperation.Arguments,
pointsToFactory,
valueContentFactory,
out _))
lock (rootOperationsNeedingAnalysis)
{
lock (rootOperationsNeedingAnalysis)
{
rootOperationsNeedingAnalysis.Add(rootOperation);
}
rootOperationsNeedingAnalysis.Add(invocationOperation.GetRoot());
}
}
},
Expand Down Expand Up @@ -181,11 +181,6 @@ public override void Initialize(AnalysisContext context)

foreach (IOperation rootOperation in rootOperationsNeedingAnalysis)
{
if (!rootOperation.TryGetEnclosingControlFlowGraph(out ControlFlowGraph cfg))
{
continue;
}

TaintedDataAnalysisResult taintedDataAnalysisResult = TaintedDataAnalysis.TryGetOrComputeResult(
cfg,
operationBlockAnalysisContext.Compilation,
Expand Down
Expand Up @@ -434,6 +434,20 @@ public static string Calculate(string unhashedNameId)
}");
}

[Fact]
public void Test_NullCfg_NoDiagnostic()
{
VerifyCSharp(@"
using System;

public class TestClass
{
public static string ContentName => ""Satya"";

public static readonly byte[] ByteArray = Convert.FromBase64String(""Some strings."");
}");
}

protected override DiagnosticAnalyzer GetBasicDiagnosticAnalyzer()
{
return new DoNotHardCodeCertificate();
Expand Down