Skip to content

Commit 95473c0

Browse files
authored
Merge pull request #16520 from michaelnebel/csharp/fixsummarizedcallabledataflow
C#: Make the flow summary filtering in the adapter.
2 parents 0dbce3d + 2449074 commit 95473c0

File tree

6 files changed

+17
-33
lines changed

6 files changed

+17
-33
lines changed

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,6 @@ newtype TReturnKind =
2424
TOutReturnKind(int i) { i = any(Parameter p | p.isOut()).getPosition() } or
2525
TRefReturnKind(int i) { i = any(Parameter p | p.isRef()).getPosition() }
2626

27-
/**
28-
* A summarized callable where the summary should be used for dataflow analysis.
29-
*/
30-
class DataFlowSummarizedCallable instanceof FlowSummary::SummarizedCallable {
31-
DataFlowSummarizedCallable() {
32-
not this.hasBody()
33-
or
34-
this.hasBody() and not this.applyGeneratedModel()
35-
}
36-
37-
string toString() { result = super.toString() }
38-
}
39-
4027
cached
4128
private module Cached {
4229
/**
@@ -47,7 +34,7 @@ private module Cached {
4734
cached
4835
newtype TDataFlowCallable =
4936
TCallable(Callable c) { c.isUnboundDeclaration() } or
50-
TSummarizedCallable(DataFlowSummarizedCallable sc) or
37+
TSummarizedCallable(FlowSummary::SummarizedCallable sc) or
5138
TFieldOrPropertyCallable(FieldOrProperty f) or
5239
TCapturedVariableCallable(LocalScopeVariable v) { v.isCaptured() }
5340

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,8 +1181,7 @@ private module Cached {
11811181
or
11821182
// Simple flow through library code is included in the exposed local
11831183
// step relation, even though flow is technically inter-procedural
1184-
FlowSummaryImpl::Private::Steps::summaryThroughStepValue(nodeFrom, nodeTo,
1185-
any(DataFlowSummarizedCallable sc))
1184+
FlowSummaryImpl::Private::Steps::summaryThroughStepValue(nodeFrom, nodeTo, _)
11861185
}
11871186

11881187
cached

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,13 @@ private predicate interpretNeutral(UnboundCallable c, string kind, string proven
554554

555555
// adapter class for converting Mad summaries to `SummarizedCallable`s
556556
private class SummarizedCallableAdapter extends SummarizedCallable {
557-
SummarizedCallableAdapter() { interpretSummary(this, _, _, _, _, _) }
557+
SummarizedCallableAdapter() {
558+
exists(Provenance provenance | interpretSummary(this, _, _, _, provenance, _) |
559+
not this.hasBody()
560+
or
561+
this.hasBody() and provenance.isManual()
562+
)
563+
}
558564

559565
private predicate relevantSummaryElementManual(
560566
string input, string output, string kind, string model

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,19 @@ private module Cached {
119119
(
120120
// Simple flow through library code is included in the exposed local
121121
// step relation, even though flow is technically inter-procedural
122-
FlowSummaryImpl::Private::Steps::summaryThroughStepTaint(nodeFrom, nodeTo,
123-
any(DataFlowSummarizedCallable sc))
122+
FlowSummaryImpl::Private::Steps::summaryThroughStepTaint(nodeFrom, nodeTo, _)
124123
or
125124
// Taint collection by adding a tainted element
126125
exists(DataFlow::ElementContent c |
127126
storeStep(nodeFrom, c, nodeTo)
128127
or
129-
FlowSummaryImpl::Private::Steps::summarySetterStep(nodeFrom, c, nodeTo,
130-
any(DataFlowSummarizedCallable sc))
128+
FlowSummaryImpl::Private::Steps::summarySetterStep(nodeFrom, c, nodeTo, _)
131129
)
132130
or
133131
exists(DataFlow::Content c |
134132
readStep(nodeFrom, c, nodeTo)
135133
or
136-
FlowSummaryImpl::Private::Steps::summaryGetterStep(nodeFrom, c, nodeTo,
137-
any(DataFlowSummarizedCallable sc))
134+
FlowSummaryImpl::Private::Steps::summaryGetterStep(nodeFrom, c, nodeTo, _)
138135
|
139136
// Taint members
140137
c = any(TaintedMember m).(FieldOrProperty).getContent()

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ Element getAssignmentTarget(Expr e) {
7777
Element getCollectionAssignmentTarget(Expr e) {
7878
// Store into collection via method
7979
exists(DataFlowPrivate::PostUpdateNode postNode |
80-
FlowSummaryImpl::Private::Steps::summarySetterStep(DataFlow::exprNode(e), _, postNode,
81-
any(DataFlowDispatch::DataFlowSummarizedCallable sc)) and
80+
FlowSummaryImpl::Private::Steps::summarySetterStep(DataFlow::exprNode(e), _, postNode, _) and
8281
result.(Variable).getAnAccess() = postNode.getPreUpdateNode().asExpr()
8382
)
8483
or

csharp/ql/test/library-tests/dataflow/external-models/steps.ql

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,17 @@ private class StepArgQualGenerated extends Method {
2525
query predicate summaryThroughStep(
2626
DataFlow::Node node1, DataFlow::Node node2, boolean preservesValue
2727
) {
28-
FlowSummaryImpl::Private::Steps::summaryThroughStepValue(node1, node2,
29-
any(DataFlowDispatch::DataFlowSummarizedCallable sc)) and
28+
FlowSummaryImpl::Private::Steps::summaryThroughStepValue(node1, node2, _) and
3029
preservesValue = true
3130
or
32-
FlowSummaryImpl::Private::Steps::summaryThroughStepTaint(node1, node2,
33-
any(DataFlowDispatch::DataFlowSummarizedCallable sc)) and
31+
FlowSummaryImpl::Private::Steps::summaryThroughStepTaint(node1, node2, _) and
3432
preservesValue = false
3533
}
3634

3735
query predicate summaryGetterStep(DataFlow::Node arg, DataFlow::Node out, Content c) {
38-
FlowSummaryImpl::Private::Steps::summaryGetterStep(arg, c, out,
39-
any(DataFlowDispatch::DataFlowSummarizedCallable sc))
36+
FlowSummaryImpl::Private::Steps::summaryGetterStep(arg, c, out, _)
4037
}
4138

4239
query predicate summarySetterStep(DataFlow::Node arg, DataFlow::Node out, Content c) {
43-
FlowSummaryImpl::Private::Steps::summarySetterStep(arg, c, out,
44-
any(DataFlowDispatch::DataFlowSummarizedCallable sc))
40+
FlowSummaryImpl::Private::Steps::summarySetterStep(arg, c, out, _)
4541
}

0 commit comments

Comments
 (0)