diff --git a/csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll b/csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll index 296df458ff2..45a73f008dd 100644 --- a/csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll +++ b/csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll @@ -586,7 +586,7 @@ private Ssa::Definition getAnSsaQualifier(Expr e, ControlFlowNode cfn) { } private AssignableAccess getATrackedAccess(Ssa::Definition def, ControlFlowNode cfn) { - result = def.getAReadAtNode(cfn) + result = def.getARead() and cfn = result.getControlFlowNode() or result = def.(Ssa::ExplicitDefinition).getADefinition().getTargetAccess() and cfn = def.getControlFlowNode() diff --git a/csharp/ql/lib/semmle/code/csharp/dataflow/Nullness.qll b/csharp/ql/lib/semmle/code/csharp/dataflow/Nullness.qll index 726f695e9b7..9af83aa767a 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/Nullness.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/Nullness.qll @@ -124,11 +124,9 @@ private predicate nonNullDef(Ssa::ExplicitDefinition def) { } /** - * Holds if `node` is a dereference `d` of SSA definition `def`. + * Holds if `d` is a dereference of SSA definition `def`. */ -private predicate dereferenceAt(ControlFlowNode node, Ssa::Definition def, Dereference d) { - d = def.getAReadAtNode(node) -} +private predicate dereferenceAt(Ssa::Definition def, Dereference d) { d = def.getARead() } private predicate isMaybeNullArgument(Ssa::ParameterDefinition def, MaybeNullExpr arg) { exists(AssignableDefinitions::ImplicitParameterDefinition pdef, Parameter p | @@ -214,7 +212,7 @@ private predicate defMaybeNull(Ssa::Definition def, ControlFlowNode node, string ) or // A variable of nullable type may be null - exists(Dereference d | dereferenceAt(_, def, d) | + exists(Dereference d | dereferenceAt(def, d) | node = def.getControlFlowNode() and d.hasNullableType() and not def instanceof Ssa::PhiNode and @@ -254,7 +252,8 @@ private module NullnessConfig implements ControlFlowReachability::ConfigSig { predicate sink(ControlFlowNode node, SsaDefinition def) { exists(Dereference d | - dereferenceAt(node, def, d) and + dereferenceAt(def, d) and + node = d.getControlFlowNode() and not d instanceof NonNullExpr ) } @@ -271,7 +270,8 @@ predicate maybeNullDeref(Dereference d, Ssa::SourceVariable v, string msg, Eleme defMaybeNull(origin, src, msg, reason) and NullnessFlow::flow(src, origin, sink, ssa) and ssa.getSourceVariable() = v and - dereferenceAt(sink, ssa, d) and + dereferenceAt(ssa, d) and + sink = d.getControlFlowNode() and not d.isAlwaysNull(v) ) } diff --git a/csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll b/csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll index 9568adf6c27..7d8809a700c 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll @@ -236,9 +236,11 @@ module Ssa { * - The reads of `this.Field` on lines 10 and 11 can be reached from the phi * node between lines 9 and 10. */ - final AssignableRead getARead() { result = this.getAReadAtNode(_) } + final AssignableRead getARead() { result = SsaImpl::getAReadAtNode(this, _) } /** + * DEPRECATED: Use `getARead()` instead. + * * Gets a read of the source variable underlying this SSA definition at * control flow node `cfn` that can be reached from this SSA definition * without passing through any other SSA definitions. Example: @@ -265,7 +267,7 @@ module Ssa { * - The reads of `this.Field` on lines 10 and 11 can be reached from the phi * node between lines 9 and 10. */ - final AssignableRead getAReadAtNode(ControlFlowNode cfn) { + deprecated final AssignableRead getAReadAtNode(ControlFlowNode cfn) { result = SsaImpl::getAReadAtNode(this, cfn) } diff --git a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll index c4d2a844103..c498d4aa3a9 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll @@ -273,7 +273,7 @@ module VariableCapture { exists(Ssa::Definition def, AssignableDefinition adef | LocalFlow::defAssigns(adef, _, _, e1) and def.getAnUltimateDefinition().(Ssa::ExplicitDefinition).getADefinition() = adef and - exists(def.getAReadAtNode(e2)) + def.getARead().getControlFlowNode() = e2 ) } diff --git a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/SignAnalysisSpecific.qll b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/SignAnalysisSpecific.qll index f6dd4911256..96245e460c7 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/SignAnalysisSpecific.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/SignAnalysisSpecific.qll @@ -245,7 +245,7 @@ private module Impl { ) } - ExprNode getARead(Ssa::Definition v) { exists(v.getAReadAtNode(result)) } + ExprNode getARead(Ssa::Definition v) { v.getARead().getControlFlowNode() = result } Field getField(ExprNode fa) { result = fa.getExpr().(FieldAccess).getTarget() } diff --git a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/SsaUtils.qll b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/SsaUtils.qll index 55267fad17c..9ff12625a06 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/SsaUtils.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/SsaUtils.qll @@ -12,13 +12,13 @@ private class ExprNode = ControlFlowNodes::ExprNode; /** An SSA variable. */ class SsaVariable extends Definition { /** Gets a read of this SSA variable. */ - ExprNode getAUse() { exists(this.getAReadAtNode(result)) } + ExprNode getAUse() { this.getARead().getControlFlowNode() = result } } /** Gets a node that reads `src` via an SSA explicit definition. */ ExprNode getAnExplicitDefinitionRead(ExprNode src) { exists(ExplicitDefinition def | - exists(def.getAReadAtNode(result)) and + def.getARead().getControlFlowNode() = result and hasChild(def.getElement(), def.getADefinition().getSource(), def.getControlFlowNode(), src) ) } @@ -27,7 +27,7 @@ ExprNode getAnExplicitDefinitionRead(ExprNode src) { * Gets an expression that equals `v - delta`. */ ExprNode ssaRead(Definition v, int delta) { - exists(v.getAReadAtNode(result)) and delta = 0 + v.getARead().getControlFlowNode() = result and delta = 0 or exists(ExprNode::AddOperation add, int d1, ConstantIntegerExpr c | result = add and