Skip to content

Commit 168f5b5

Browse files
committed
C#: Add dataflow support for collection expressions.
1 parent 8eb89cf commit 168f5b5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ module LocalFlow {
250250
scope = e2 and
251251
isSuccessor = true
252252
or
253+
e1 = e2.(CollectionExpression).getAnElement().(SpreadElementExpr).getExpr() and
254+
scope = e2 and
255+
isSuccessor = true
256+
or
253257
exists(WithExpr we |
254258
scope = we and
255259
isSuccessor = true
@@ -738,6 +742,15 @@ private predicate fieldOrPropertyRead(Expr e1, Content c, FieldOrPropertyRead e2
738742
)
739743
}
740744

745+
/**
746+
* Holds if `ce` is a collection expression that adds `src` to the collection `ce`.
747+
*/
748+
private predicate collectionStore(Expr src, CollectionExpression ce) {
749+
// Collection expression, `[1, src, 3]`
750+
src = ce.getAnElement() and
751+
not src instanceof SpreadElementExpr
752+
}
753+
741754
/**
742755
* Holds if `e` is an expression that adds `src` to array `a`.
743756
*
@@ -1799,6 +1812,11 @@ private class StoreStepConfiguration extends ControlFlowReachabilityConfiguratio
17991812
or
18001813
exactScope = false and
18011814
isSuccessor = true and
1815+
collectionStore(e1, e2) and
1816+
scope = e2
1817+
or
1818+
exactScope = false and
1819+
isSuccessor = true and
18021820
isParamsArg(e2, e1, _) and
18031821
scope = e2
18041822
}
@@ -1823,6 +1841,10 @@ predicate storeStep(Node node1, ContentSet c, Node node2) {
18231841
arrayStore(_, node1.asExpr(), node.getExpr(), postUpdate) and c instanceof ElementContent
18241842
)
18251843
or
1844+
exists(StoreStepConfiguration x | hasNodePath(x, node1, node2) |
1845+
collectionStore(node1.asExpr(), node2.asExpr()) and c instanceof ElementContent
1846+
)
1847+
or
18261848
exists(StoreStepConfiguration x, Expr arg, ControlFlow::Node callCfn |
18271849
x.hasExprPath(arg, node1.(ExprNode).getControlFlowNode(), _, callCfn) and
18281850
node2 = TParamsArgumentNode(callCfn) and

0 commit comments

Comments
 (0)