Skip to content

Commit 28aa9b2

Browse files
committed
C#: Emulate that some methods don't have a body (so generated summaries will be applied)
1 parent 14cffc3 commit 28aa9b2

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ module TaintConfig implements DataFlow::ConfigSig {
2121
module Taint = TaintTracking::Global<TaintConfig>;
2222

2323
/**
24-
* Simulate that methods with summaries are not included in the source code.
25-
* This is relevant for dataflow analysis using summaries tagged as generated.
24+
* Emulate that methods with summaries do not have a body.
25+
* This is relevant for dataflow analysis using summaries with a generated like
26+
* provenance as generated summaries are only applied, if a
27+
* callable does not have a body.
2628
*/
27-
private class MyMethod extends Method {
28-
override predicate fromSource() { none() }
29+
private class MixedFlowArgs extends Method {
30+
MixedFlowArgs() { this.hasFullyQualifiedName("My.Qltest", "G", "MixedFlowArgs") }
31+
32+
override predicate hasBody() { none() }
2933
}
3034

3135
from Taint::PathNode source, Taint::PathNode sink

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ import semmle.code.csharp.dataflow.FlowSummary
66
import semmle.code.csharp.dataflow.internal.DataFlowDispatch as DataFlowDispatch
77
import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
88

9+
/**
10+
* Emulate that methods with summaries do not have a body.
11+
* This is relevant for dataflow analysis using summaries with a generated like
12+
* provenance as generated summaries are only applied, if a
13+
* callable does not have a body.
14+
*/
15+
private class StepArgQualGenerated extends Method {
16+
StepArgQualGenerated() {
17+
exists(string name |
18+
this.hasFullyQualifiedName("My.Qltest", "C", name) and name.matches("StepArgQualGenerated%")
19+
)
20+
}
21+
22+
override predicate hasBody() { none() }
23+
}
24+
925
query predicate summaryThroughStep(
1026
DataFlow::Node node1, DataFlow::Node node2, boolean preservesValue
1127
) {

0 commit comments

Comments
 (0)