public bool TryGetOrComputeResult( ImmutableArray <IOperation> operationBlocks, IMethodSymbol containingMethod, bool trackInstanceFields, out DataFlowAnalysisResult <DisposeBlockAnalysisResult, DisposeAbstractValue> disposeAnalysisResult, out DataFlowAnalysisResult <PointsToBlockAnalysisResult, PointsToAbstractValue> pointsToAnalysisResult, out ImmutableDictionary <IFieldSymbol, PointsToAbstractValue> trackedInstanceFieldPointsToMap) { foreach (var operationRoot in operationBlocks) { IBlockOperation topmostBlock = operationRoot.GetTopmostParentBlock(); if (topmostBlock != null) { var cfg = ControlFlowGraph.Create(topmostBlock); // Invoking an instance method may likely invalidate all the instance field analysis state, i.e. // reference type fields might be re-assigned to point to different objects in the called method. // An optimistic points to analysis assumes that the points to values of instance fields don't change on invoking an instance method. // A pessimistic points to analysis resets all the instance state and assumes the instance field might point to any object, hence has unknown state. // For dispose analysis, we want to perform an optimistic points to analysis as we assume a disposable field is not likely to be re-assigned to a separate object in helper method invocations in Dispose. pointsToAnalysisResult = PointsToAnalysis.GetOrComputeResult(cfg, containingMethod, _wellKnownTypeProvider, pessimisticAnalysis: false); disposeAnalysisResult = DisposeAnalysis.GetOrComputeResult(cfg, containingMethod, _wellKnownTypeProvider, _disposeOwnershipTransferLikelyTypes, pointsToAnalysisResult, trackInstanceFields, out trackedInstanceFieldPointsToMap); return(true); } } disposeAnalysisResult = null; pointsToAnalysisResult = null; trackedInstanceFieldPointsToMap = null; return(false); }
protected override ParameterValidationAnalysisResult ToResult( ParameterValidationAnalysisContext analysisContext, DataFlowAnalysisResult <ParameterValidationBlockAnalysisResult, ParameterValidationAbstractValue> dataFlowAnalysisResult) { analysisContext = analysisContext.WithTrackHazardousParameterUsages(); var newOperationVisitor = new ParameterValidationDataFlowOperationVisitor(analysisContext); foreach (var block in analysisContext.ControlFlowGraph.Blocks) { var data = new ParameterValidationAnalysisData(dataFlowAnalysisResult[block].Data); data = Flow(newOperationVisitor, block, data); if (block.FallThroughSuccessor != null) { var fallThroughData = block.ConditionalSuccessor != null?AnalysisDomain.Clone(data) : data; _ = FlowBranch(newOperationVisitor, block.FallThroughSuccessor, fallThroughData); } if (block.ConditionalSuccessor != null) { _ = FlowBranch(newOperationVisitor, block.ConditionalSuccessor, data); } } return(new ParameterValidationAnalysisResult(dataFlowAnalysisResult, newOperationVisitor.HazardousParameterUsages)); }
protected DataFlowAnalysisResult CheckResult(DataFlowAnalysisResult result, string[] model) { if (result == null) { Assert.Fail("The result is null"); return(null); } Console.WriteLine(); var text = result.ToText().ToList(); foreach (var line in text) { Console.WriteLine(line); } if (model == null || model.Length == 0 || (model.Length == 1 && String.IsNullOrEmpty(model[0]))) { Assert.That(text, Is.EqualTo(Enumerable.Empty <string>())); } else { Assert.That(text, Is.EqualTo(model)); } return(result); }
private static bool HasLiteralStateLoss(DataFlowAnalysisResult <ValueContentBlockAnalysisResult, ValueContentAbstractValue> valueContentAnalysis) { /* * Проверяем, что в ходе анализа не было потери списка возможных литералов. * Например, проявляется при достижении ограничения на количество возможных литералов * https://github.com/dotnet/roslyn-analyzers/blob/2a72252ddcd7c3ebbbb842239e67116a3678f610/src/Utilities/FlowAnalysis/FlowAnalysis/Analysis/ValueContentAnalysis/ValueContentAbstractValue.cs#L171 */ foreach (var block in valueContentAnalysis.ControlFlowGraph.Blocks) { foreach (var keyValue in valueContentAnalysis[block].Data) { var key = keyValue.Key; var value = keyValue.Value; if (value.NonLiteralState == ValueContainsNonLiteralState.Maybe) { if (block.Predecessors.All(pred => valueContentAnalysis[pred.Source].Data.TryGetValue(key, out var predValue) && predValue.NonLiteralState == ValueContainsNonLiteralState.No)) { return(true); } } } } return(false); }
public ParameterValidationAnalysisResult( DataFlowAnalysisResult <ParameterValidationBlockAnalysisResult, ParameterValidationAbstractValue> parameterValidationAnalysisResult, ImmutableDictionary <IParameterSymbol, SyntaxNode> hazardousParameterUsages) : base(parameterValidationAnalysisResult) { HazardousParameterUsages = hazardousParameterUsages; }
public TaintedDataAnalysisResult( DataFlowAnalysisResult <TaintedDataBlockAnalysisResult, TaintedDataAbstractValue> dataFlowAnalysisResult, ImmutableArray <TaintedDataSourceSink> taintedDataSourceSinks) : base(dataFlowAnalysisResult) { this.TaintedDataSourceSinks = taintedDataSourceSinks; }
public NullDataFlowOperationVisitor( AbstractDomain <NullAbstractValue> valueDomain, INamedTypeSymbol containingTypeSymbol, DataFlowAnalysisResult <PointsToAnalysis.PointsToBlockAnalysisResult, PointsToAnalysis.PointsToAbstractValue> pointsToAnalysisResultOpt) : base(valueDomain, containingTypeSymbol, nullAnalysisResultOpt: null, pointsToAnalysisResultOpt: pointsToAnalysisResultOpt) { }
private static DataFlowAnalysisResult <DisposeBlockAnalysisResult, DisposeAbstractValue> GetOrComputeResultCore( ControlFlowGraph cfg, INamedTypeSymbol iDisposable, INamedTypeSymbol taskType, ImmutableHashSet <INamedTypeSymbol> collectionTypes, ImmutableHashSet <INamedTypeSymbol> disposeOwnershipTransferLikelyTypes, ISymbol owningSymbol, DataFlowAnalysisResult <PointsToAnalysis.PointsToBlockAnalysisResult, PointsToAnalysis.PointsToAbstractValue> pointsToAnalysisResult, DataFlowAnalysisResult <NullAnalysis.NullBlockAnalysisResult, NullAnalysis.NullAbstractValue> nullAnalysisResultOpt, bool trackInstanceFields, out ImmutableDictionary <IFieldSymbol, PointsToAnalysis.PointsToAbstractValue> trackedInstanceFieldPointsToMap) { Debug.Assert(cfg != null); Debug.Assert(iDisposable != null); Debug.Assert(owningSymbol != null); Debug.Assert(pointsToAnalysisResult != null); var operationVisitor = new DisposeDataFlowOperationVisitor(iDisposable, taskType, collectionTypes, disposeOwnershipTransferLikelyTypes, DisposeAbstractValueDomain.Default, owningSymbol, trackInstanceFields, pointsToAnalysisResult, nullAnalysisResultOpt); var disposeAnalysis = new DisposeAnalysis(DisposeAnalysisDomainInstance, operationVisitor); var result = disposeAnalysis.GetOrComputeResultCore(cfg); trackedInstanceFieldPointsToMap = trackInstanceFields ? operationVisitor.TrackedInstanceFieldPointsToMap : null; return(result); }
public PointsToDataFlowOperationVisitor( PointsToAbstractValueDomain valueDomain, INamedTypeSymbol containingTypeSymbol, DataFlowAnalysisResult <NullAnalysis.NullBlockAnalysisResult, NullAnalysis.NullAbstractValue> nullAnalysisResultOpt) : base(valueDomain, containingTypeSymbol, nullAnalysisResultOpt: nullAnalysisResultOpt, pointsToAnalysisResultOpt: null) { }
private static ParameterValidationResultWithHazardousUsages GetOrComputeResult( ControlFlowGraph cfg, ISymbol owningSymbol, WellKnownTypeProvider wellKnownTypeProvider, DataFlowAnalysisResult <NullAnalysis.NullBlockAnalysisResult, NullAnalysis.NullAbstractValue> nullAnalysisResult, DataFlowAnalysisResult <PointsToAnalysis.PointsToBlockAnalysisResult, PointsToAnalysis.PointsToAbstractValue> pointsToAnalysisResult, Func <IBlockOperation, IMethodSymbol, ParameterValidationResultWithHazardousUsages> getOrComputeLocationAnalysisResultOpt, bool pessimisticAnalysis) { var operationVisitor = new ParameterValidationDataFlowOperationVisitor(ParameterValidationAbstractValueDomain.Default, owningSymbol, wellKnownTypeProvider, getOrComputeLocationAnalysisResultOpt, nullAnalysisResult, pointsToAnalysisResult, pessimisticAnalysis); var analysis = new ParameterValidationAnalysis(ParameterValidationAnalysisDomainInstance, operationVisitor); var analysisResult = analysis.GetOrComputeResultCore(cfg, cacheResult: true); var newOperationVisitor = new ParameterValidationDataFlowOperationVisitor(ParameterValidationAbstractValueDomain.Default, owningSymbol, wellKnownTypeProvider, getOrComputeLocationAnalysisResultOpt, nullAnalysisResult, pointsToAnalysisResult, pessimisticAnalysis, trackHazardousParameterUsages: true); var resultBuilder = new DataFlowAnalysisResultBuilder <ParameterValidationAnalysisData>(); foreach (var block in cfg.Blocks) { var data = ParameterValidationAnalysisDomainInstance.Clone(analysisResult[block].InputData); data = Flow(newOperationVisitor, block, data); } return(new ParameterValidationResultWithHazardousUsages(analysisResult, newOperationVisitor.HazardousParameterUsages)); }
public override TaintedDataAnalysisContext ForkForInterproceduralAnalysis( IMethodSymbol invokedMethod, ControlFlowGraph invokedCfg, IOperation operation, PointsToAnalysisResult pointsToAnalysisResultOpt, DataFlowAnalysisResult <CopyBlockAnalysisResult, CopyAbstractValue> copyAnalysisResultOpt, DataFlowAnalysisResult <ValueContentBlockAnalysisResult, ValueContentAbstractValue> valueContentAnalysisResultOpt, InterproceduralTaintedDataAnalysisData interproceduralAnalysisData) { return(new TaintedDataAnalysisContext( this.ValueDomain, this.WellKnownTypeProvider, invokedCfg, invokedMethod, this.AnalyzerOptions, this.InterproceduralAnalysisConfiguration, this.PessimisticAnalysis, copyAnalysisResultOpt, pointsToAnalysisResultOpt, valueContentAnalysisResultOpt, this.TryGetOrComputeAnalysisResult, this.ControlFlowGraph, interproceduralAnalysisData, this.SourceInfos, this.SanitizerInfos, this.SinkInfos)); }
public DisposeDataFlowOperationVisitor( INamedTypeSymbol iDisposable, INamedTypeSymbol taskType, ImmutableHashSet <INamedTypeSymbol> collectionTypes, ImmutableHashSet <INamedTypeSymbol> disposeOwnershipTransferLikelyTypes, DisposeAbstractValueDomain valueDomain, ISymbol owningSymbol, bool trackInstanceFields, DataFlowAnalysisResult <PointsToBlockAnalysisResult, PointsToAbstractValue> pointsToAnalysisResult, DataFlowAnalysisResult <NullBlockAnalysisResult, NullAbstractValue> nullAnalysisResultOpt) : base(valueDomain, owningSymbol, pessimisticAnalysis, nullAnalysisResultOpt: nullAnalysisResultOpt, pointsToAnalysisResultOpt: pointsToAnalysisResult) { Debug.Assert(iDisposable != null); Debug.Assert(collectionTypes.All(ct => ct.TypeKind == TypeKind.Interface)); Debug.Assert(disposeOwnershipTransferLikelyTypes != null); Debug.Assert(pointsToAnalysisResult != null); _iDisposable = iDisposable; _taskType = taskType; _collectionTypes = collectionTypes; _disposeOwnershipTransferLikelyTypes = disposeOwnershipTransferLikelyTypes; if (trackInstanceFields) { _trackedInstanceFieldLocationsOpt = new Dictionary <IFieldSymbol, PointsToAbstractValue>(); } }
public ParameterValidationResultWithHazardousUsages( DataFlowAnalysisResult <ParameterValidationBlockAnalysisResult, ParameterValidationAbstractValue> parameterValidationAnalysisResult, ImmutableDictionary <IParameterSymbol, SyntaxNode> hazardousParameterUsages) { ParameterValidationAnalysisResult = parameterValidationAnalysisResult; HazardousParameterUsages = hazardousParameterUsages; }
public override TaintedDataAnalysisContext ForkForInterproceduralAnalysis( IMethodSymbol invokedMethod, ControlFlowGraph invokedCfg, IOperation operation, PointsToAnalysisResult pointsToAnalysisResultOpt, DataFlowAnalysisResult <CopyBlockAnalysisResult, CopyAbstractValue> copyAnalysisResultOpt, DataFlowAnalysisResult <ValueContentBlockAnalysisResult, ValueContentAbstractValue> valueContentAnalysisResultOpt, InterproceduralTaintedDataAnalysisData interproceduralAnalysisData) { Debug.Assert(copyAnalysisResultOpt == null); // Just because we're not passing this argument along. Debug.Assert(valueContentAnalysisResultOpt == null); return(new TaintedDataAnalysisContext( this.ValueDomain, this.WellKnownTypeProvider, invokedCfg, invokedMethod, this.InterproceduralAnalysisConfiguration, this.PessimisticAnalysis, pointsToAnalysisResultOpt, this.TryGetOrComputeAnalysisResult, this.ControlFlowGraph, interproceduralAnalysisData, this.SourceInfos, this.SanitizerInfos, this.SinkInfos)); }
internal DisposeAnalysisResult( DataFlowAnalysisResult <DisposeBlockAnalysisResult, DisposeAbstractValue> coreDisposeAnalysisResult, ImmutableDictionary <IFieldSymbol, PointsToAnalysis.PointsToAbstractValue> trackedInstanceFieldPointsToMap) : base(coreDisposeAnalysisResult) { TrackedInstanceFieldPointsToMap = trackedInstanceFieldPointsToMap; }
public bool TryGetOrComputeResult( ImmutableArray <IOperation> operationBlocks, IMethodSymbol containingMethod, out DataFlowAnalysisResult <DisposeBlockAnalysisResult, DisposeAbstractValue> disposeAnalysisResult) { return(TryGetOrComputeResult(operationBlocks, containingMethod, out disposeAnalysisResult, out var _)); }
protected override TaintedDataAnalysisResult ToResult( TaintedDataAnalysisContext analysisContext, DataFlowAnalysisResult <TaintedDataBlockAnalysisResult, TaintedDataAbstractValue> dataFlowAnalysisResult) { TaintedDataOperationVisitor visitor = (TaintedDataOperationVisitor)this.OperationVisitor; return(new TaintedDataAnalysisResult(dataFlowAnalysisResult, visitor.GetTaintedDataSourceSinkEntries())); }
public override GlobalFlowStateDictionaryAnalysisContext ForkForInterproceduralAnalysis( IMethodSymbol invokedMethod, ControlFlowGraph invokedCfg, PointsToAnalysisResult?pointsToAnalysisResult, DataFlowAnalysisResult <CopyBlockAnalysisResult, CopyAbstractValue>?copyAnalysisResult, DataFlowAnalysisResult <ValueContentBlockAnalysisResult, ValueContentAbstractValue>?valueContentAnalysisResult, InterproceduralAnalysisData <GlobalFlowStateDictionaryAnalysisData, GlobalFlowStateDictionaryAnalysisContext, GlobalFlowStateDictionaryAnalysisValue>?interproceduralAnalysisData) => new(
public NullDataFlowOperationVisitor( NullAbstractValueDomain valueDomain, ISymbol owningSymbol, bool pessimisticAnalysis, DataFlowAnalysisResult <PointsToAnalysis.PointsToBlockAnalysisResult, PointsToAnalysis.PointsToAbstractValue> pointsToAnalysisResultOpt) : base(valueDomain, owningSymbol, pessimisticAnalysis, nullAnalysisResultOpt: null, pointsToAnalysisResultOpt: pointsToAnalysisResultOpt) { }
public StringContentDataFlowOperationVisitor( StringContentAbstractValueDomain valueDomain, INamedTypeSymbol containingTypeSymbol, DataFlowAnalysisResult <NullAnalysis.NullBlockAnalysisResult, NullAnalysis.NullAbstractValue> nullAnalysisResultOpt, DataFlowAnalysisResult <PointsToAnalysis.PointsToBlockAnalysisResult, PointsToAnalysis.PointsToAbstractValue> pointsToAnalysisResultOpt) : base(valueDomain, containingTypeSymbol, nullAnalysisResultOpt, pointsToAnalysisResultOpt) { }
public PointsToDataFlowOperationVisitor( PointsToAbstractValueDomain valueDomain, ISymbol owningSymbol, bool pessimisticAnalysis, DataFlowAnalysisResult <NullAnalysis.NullBlockAnalysisResult, NullAnalysis.NullAbstractValue> nullAnalysisResultOpt) : base(valueDomain, owningSymbol, pessimisticAnalysis, nullAnalysisResultOpt: nullAnalysisResultOpt, pointsToAnalysisResultOpt: null) { }
protected override PropertySetAnalysisResult ToResult( PropertySetAnalysisContext analysisContext, DataFlowAnalysisResult <PropertySetBlockAnalysisResult, PropertySetAbstractValue> dataFlowAnalysisResult) { return(new PropertySetAnalysisResult( dataFlowAnalysisResult, ((PropertySetDataFlowOperationVisitor)this.OperationVisitor).HazardousUsages)); }
public CopyDataFlowOperationVisitor( CopyAbstractValueDomain valueDomain, ISymbol owningSymbol, WellKnownTypeProvider wellKnownTypeProvider, bool pessimisticAnalysis, DataFlowAnalysisResult <PointsToAnalysis.PointsToBlockAnalysisResult, PointsToAnalysis.PointsToAbstractValue> pointsToAnalysisResultOpt) : base(valueDomain, owningSymbol, wellKnownTypeProvider, pessimisticAnalysis, predicateAnalysis: true, copyAnalysisResultOpt: null, pointsToAnalysisResultOpt: pointsToAnalysisResultOpt) { }
public bool TryGetOrComputeResult( ImmutableArray <IOperation> operationBlocks, IMethodSymbol containingMethod, out DataFlowAnalysisResult <DisposeBlockAnalysisResult, DisposeAbstractValue> disposeAnalysisResult, out DataFlowAnalysisResult <PointsToBlockAnalysisResult, PointsToAbstractValue> pointsToAnalysisResult) { return(TryGetOrComputeResult(operationBlocks, containingMethod, trackInstanceFields: false, disposeAnalysisResult: out disposeAnalysisResult, pointsToAnalysisResult: out pointsToAnalysisResult, trackedInstanceFieldPointsToMap: out var _)); }
public StringContentDataFlowOperationVisitor( StringContentAbstractValueDomain valueDomain, ISymbol owningSymbol, bool pessimisticAnalysis, DataFlowAnalysisResult <NullAnalysis.NullBlockAnalysisResult, NullAnalysis.NullAbstractValue> nullAnalysisResultOpt, DataFlowAnalysisResult <PointsToAnalysis.PointsToBlockAnalysisResult, PointsToAnalysis.PointsToAbstractValue> pointsToAnalysisResultOpt) : base(valueDomain, owningSymbol, pessimisticAnalysis, nullAnalysisResultOpt, pointsToAnalysisResultOpt) { }
public static DataFlowAnalysisResult <PointsToBlockAnalysisResult, PointsToAbstractValue> GetOrComputeResult( ControlFlowGraph cfg, INamedTypeSymbol containingTypeSymbol, DataFlowAnalysisResult <NullAnalysis.NullBlockAnalysisResult, NullAnalysis.NullAbstractValue> nullAnalysisResultOpt = null) { var operationVisitor = new PointsToDataFlowOperationVisitor(PointsToAbstractValueDomain.Default, containingTypeSymbol, nullAnalysisResultOpt); var pointsToAnalysis = new PointsToAnalysis(PointsToAnalysisDomainInstance, operationVisitor); return(pointsToAnalysis.GetOrComputeResultCore(cfg)); }
public static DataFlowAnalysisResult <DisposeBlockAnalysisResult, DisposeAbstractValue> GetOrComputeResult( ControlFlowGraph cfg, ISymbol owningSymbol, WellKnownTypeProvider wellKnownTypeProvider, ImmutableHashSet <INamedTypeSymbol> disposeOwnershipTransferLikelyTypes, DataFlowAnalysisResult <PointsToAnalysis.PointsToBlockAnalysisResult, PointsToAnalysis.PointsToAbstractValue> pointsToAnalysisResult) { return(GetOrComputeResultCore(cfg, owningSymbol, wellKnownTypeProvider, disposeOwnershipTransferLikelyTypes, pointsToAnalysisResult, trackInstanceFields: false, trackedInstanceFieldPointsToMap: out var _)); }
public static DataFlowAnalysisResult <StringContentBlockAnalysisResult, StringContentAbstractValue> GetOrComputeResult( ControlFlowGraph cfg, INamedTypeSymbol containingTypeSymbol, DataFlowAnalysisResult <NullAnalysis.NullBlockAnalysisResult, NullAnalysis.NullAbstractValue> nullAnalysisResultOpt = null, DataFlowAnalysisResult <PointsToAnalysis.PointsToBlockAnalysisResult, PointsToAnalysis.PointsToAbstractValue> pointsToAnalysisResultOpt = null) { var operationVisitor = new StringContentDataFlowOperationVisitor(StringContentAbstractValueDomain.Default, containingTypeSymbol, nullAnalysisResultOpt, pointsToAnalysisResultOpt); var nullAnalysis = new StringContentAnalysis(s_StringContentAnalysisDomain, operationVisitor); return(nullAnalysis.GetOrComputeResultCore(cfg)); }
internal PointsToAnalysisResult( DataFlowAnalysisResult <PointsToBlockAnalysisResult, PointsToAbstractValue> corePointsToAnalysisResult, ImmutableDictionary <IOperation, ImmutableHashSet <AbstractLocation> > escapedLocationsThroughOperationsMap, ImmutableDictionary <IOperation, ImmutableHashSet <AbstractLocation> > escapedLocationsThroughReturnValuesMap, ImmutableDictionary <AnalysisEntity, ImmutableHashSet <AbstractLocation> > escapedLocationsThroughEntitiesMap) : base(corePointsToAnalysisResult) { _escapedLocationsThroughOperationsMap = escapedLocationsThroughOperationsMap; _escapedLocationsThroughReturnValuesMap = escapedLocationsThroughReturnValuesMap; _escapedLocationsThroughEntitiesMap = escapedLocationsThroughEntitiesMap; }
public static DataFlowAnalysisResult <NullBlockAnalysisResult, NullAbstractValue> GetOrComputeResult( ControlFlowGraph cfg, ISymbol owningSymbol, bool pessimisticAnalysis = true, DataFlowAnalysisResult <PointsToAnalysis.PointsToBlockAnalysisResult, PointsToAnalysis.PointsToAbstractValue> pointsToAnalysisResultOpt = null) { var operationVisitor = new NullDataFlowOperationVisitor(NullAbstractValueDomain.Default, owningSymbol, pessimisticAnalysis, pointsToAnalysisResultOpt); var nullAnalysis = new NullAnalysis(NullAnalysisDomainInstance, operationVisitor); return(nullAnalysis.GetOrComputeResultCore(cfg)); }