Skip to content

Commit a031160

Browse files
committed
C#: Add missing post-update nodes for reverse array stores a[i].f = x
1 parent e47e824 commit a031160

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -710,25 +710,28 @@ private module Cached {
710710
TObjectInitializerNode(ControlFlow::Nodes::ElementNode cfn) {
711711
cfn.getElement().(ObjectCreation).hasInitializer()
712712
} or
713-
TExprPostUpdateNode(ControlFlow::Nodes::ElementNode cfn) {
714-
exists(Argument a, Type t |
715-
a = cfn.getElement() and
716-
t = a.stripCasts().getType()
717-
|
718-
t instanceof RefType and
719-
not t instanceof NullType
713+
TExprPostUpdateNode(ControlFlow::Nodes::ExprNode cfn) {
714+
exists(Expr e | e = cfn.getExpr() |
715+
exists(Type t | t = e.(Argument).stripCasts().getType() |
716+
t instanceof RefType and
717+
not t instanceof NullType
718+
or
719+
t = any(TypeParameter tp | not tp.isValueType())
720+
)
720721
or
721-
t = any(TypeParameter tp | not tp.isValueType())
722-
)
723-
or
724-
fieldOrPropertyStore(_, _, _, cfn.getElement(), true)
725-
or
726-
arrayStore(_, _, cfn.getElement(), true)
727-
or
728-
exists(TExprPostUpdateNode upd, FieldOrPropertyAccess fla |
729-
upd = TExprPostUpdateNode(fla.getAControlFlowNode())
730-
|
731-
cfn.getElement() = fla.getQualifier()
722+
fieldOrPropertyStore(_, _, _, e, true)
723+
or
724+
arrayStore(_, _, e, true)
725+
or
726+
// needed for reverse stores; e.g. `x.f1.f2 = y` induces
727+
// a store step of `f1` into `x`
728+
exists(TExprPostUpdateNode upd, Expr read |
729+
upd = TExprPostUpdateNode(read.getAControlFlowNode())
730+
|
731+
fieldOrPropertyRead(e, _, read)
732+
or
733+
arrayRead(e, read)
734+
)
732735
)
733736
} or
734737
TSummaryNode(FlowSummary::SummarizedCallable c, FlowSummaryImpl::Private::SummaryNodeState state) {

0 commit comments

Comments
 (0)