Skip to content

Commit c3007ff

Browse files
authored
Merge pull request #7468 from michaelnebel/csharp-foreach-dataflow
C#: Re-factor the ForEachCapture query to use MaD flow summaries.
2 parents de1697a + 748b2d2 commit c3007ff

File tree

2 files changed

+5
-28
lines changed

2 files changed

+5
-28
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/LibraryTypeDataFlow.qll

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -478,25 +478,6 @@ class SystemTextStringBuilderFlow extends LibraryTypeDataFlow, SystemTextStringB
478478
class IEnumerableFlow extends LibraryTypeDataFlow, RefType {
479479
IEnumerableFlow() { this.getABaseType*() instanceof SystemCollectionsIEnumerableInterface }
480480

481-
override predicate callableFlow(
482-
CallableFlowSource source, AccessPath sourceAp, CallableFlowSink sink, AccessPath sinkAp,
483-
SourceDeclarationCallable c, boolean preservesValue
484-
) {
485-
preservesValue = true and
486-
exists(string name, int arity |
487-
arity = c.getNumberOfParameters() and
488-
c = this.getAMethod() and
489-
c.getUndecoratedName() = name
490-
|
491-
name = "Add" and
492-
arity = 1 and
493-
source = TCallableFlowSourceArg(0) and
494-
sourceAp = AccessPath::empty() and
495-
sink instanceof CallableFlowSinkQualifier and
496-
sinkAp = AccessPath::element()
497-
)
498-
}
499-
500481
override predicate clearsContent(
501482
CallableFlowSource source, Content content, SourceDeclarationCallable callable
502483
) {

csharp/ql/src/Language Abuse/ForeachCapture.ql

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
*/
1313

1414
import csharp
15-
import semmle.code.csharp.dataflow.LibraryTypeDataFlow
15+
import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
16+
import semmle.code.csharp.dataflow.internal.DataFlowPrivate as DataFlowPrivate
1617
import semmle.code.csharp.frameworks.system.Collections
1718
import semmle.code.csharp.frameworks.system.collections.Generic
1819

@@ -74,14 +75,9 @@ Element getAssignmentTarget(Expr e) {
7475

7576
Element getCollectionAssignmentTarget(Expr e) {
7677
// Store into collection via method
77-
exists(
78-
MethodCall mc, Method m, LibraryTypeDataFlow ltdf, CallableFlowSource source,
79-
CallableFlowSink sink
80-
|
81-
m = mc.getTarget().getUnboundDeclaration() and
82-
ltdf.callableFlow(source, AccessPath::empty(), sink, AccessPath::element(), m, _) and
83-
e = source.getSource(mc) and
84-
result.(Variable).getAnAccess() = sink.getSink(mc)
78+
exists(DataFlowPrivate::PostUpdateNode postNode |
79+
FlowSummaryImpl::Private::Steps::summarySetterStep(DataFlow::exprNode(e), _, postNode) and
80+
result.(Variable).getAnAccess() = postNode.getPreUpdateNode().asExpr()
8581
)
8682
or
8783
// Array initializer

0 commit comments

Comments
 (0)