Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ public override void Initialize(AnalysisContext context)
}

return PropertySetAbstractValue.GetInstance(kind);
});
},
constructorMethod => constructorMethod.Parameters.IsEmpty
? PropertySetAbstractValue.GetInstance(PropertySetAbstractValueKind.Unflagged)
: null);

var rootOperationsNeedingAnalysis = PooledHashSet<(IOperation, ISymbol)>.GetInstance();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public sealed class DoNotSetSwitch : DiagnosticAnalyzer
}.Select(
(o) => new KeyValuePair<string, (bool, DiagnosticDescriptor)>(o.Item1, o.Item2)));

// Per-analyzer observer keeps performance assertions isolated across concurrent tests.
internal Action? ValueContentAnalysisStarted { get; set; }

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(
DoNotDisableSchUseStrongCryptoRule,
DoNotDisableSpmSecurityProtocolsRule);
Expand Down Expand Up @@ -107,14 +110,26 @@ public override void Initialize(AnalysisContext context)
return;
}

var values = invocationOperation.Arguments.Select(s => s.Value.ConstantValue).ToArray();
Optional<object?> switchNameValue = invocationOperation.Arguments[0].Value.ConstantValue;
if (switchNameValue.HasValue &&
(switchNameValue.Value is not string name || !BadSwitches.ContainsKey(name)))
{
return;
}

Optional<object?> switchValueConstant = invocationOperation.Arguments[1].Value.ConstantValue;
if (switchValueConstant.HasValue &&
switchValueConstant.Value is bool value &&
BadSwitches.Values.All(pair => pair.BadValue != value))
{
return;
}

if (values[0].HasValue &&
values[1].HasValue)
if (switchNameValue.HasValue && switchValueConstant.HasValue)
{
if (values[0].Value is string switchName &&
if (switchNameValue.Value is string switchName &&
BadSwitches.TryGetValue(switchName, out var pair) &&
pair.BadValue.Equals(values[1].Value) &&
pair.BadValue.Equals(switchValueConstant.Value) &&
!IsConfiguredToSkipAnalysis(pair.Rule, operationAnalysisContext))
{
operationAnalysisContext.ReportDiagnostic(
Expand All @@ -125,6 +140,7 @@ public override void Initialize(AnalysisContext context)
}
else if (invocationOperation.TryGetEnclosingControlFlowGraph(out var cfg))
{
ValueContentAnalysisStarted?.Invoke();
var valueContentResult = ValueContentAnalysis.TryGetOrComputeResult(
cfg,
operationAnalysisContext.ContainingSymbol,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
Expand Down Expand Up @@ -57,6 +58,9 @@ internal class DoNotUseInsecureDeserializerJsonNetWithoutBinder : DiagnosticAnal
DefinitelyInsecureSerializer,
MaybeInsecureSerializer);

// Per-analyzer observer keeps performance assertions isolated across concurrent tests.
internal Action? ValueContentAnalysisStarted { get; set; }

/// <summary>
/// PropertySetAbstractValue index for TypeNameHandling property.
/// </summary>
Expand Down Expand Up @@ -210,7 +214,8 @@ public override void Initialize(AnalysisContext context)
SupportedDiagnostics,
rootOperationsNeedingAnalysis.First().Operation,
compilationAnalysisContext.Compilation,
defaultInterproceduralAnalysisKind: InterproceduralAnalysisKind.ContextSensitive));
defaultInterproceduralAnalysisKind: InterproceduralAnalysisKind.ContextSensitive),
onValueContentAnalysis: ValueContentAnalysisStarted);
}

if (allResults == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ public override void Initialize(AnalysisContext context)
}

return PropertySetAbstractValue.GetInstance(kind);
});
},
constructorMethod => constructorMethod.Parameters.Length < 3
? PropertySetAbstractValue.GetInstance(
DefaultIterationCount >= sufficientIterationCount
? PropertySetAbstractValueKind.Unflagged
: PropertySetAbstractValueKind.Flagged)
: null);
var propertyMappers = new PropertyMapperCollection(
new PropertyMapper(
"IterationCount",
Expand Down
Loading
Loading