Skip to content

Commit 0e3fc46

Browse files
michaelnebelhvitved
authored andcommitted
C#: Use SummarizedCallable external instead of the internal.
1 parent b578fcb commit 0e3fc46

File tree

9 files changed

+35
-49
lines changed

9 files changed

+35
-49
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,7 @@ newtype TDataFlowCallable =
256256

257257
class DataFlowCallable extends TDataFlowCallable {
258258
/** Get the underlying source code callable, if any. */
259-
DotNet::Callable asCallable() {
260-
this = TDotNetCallable(result) or this = TSummarizedCallable(result)
261-
}
259+
DotNet::Callable asCallable() { this = TDotNetCallable(result) }
262260

263261
/** Get the underlying summarized callable, if any. */
264262
FlowSummary::SummarizedCallable asSummarizedCallable() { this = TSummarizedCallable(result) }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,10 @@ private predicate fieldOrPropertyStore(Expr e, Content c, Expr src, Expr q, bool
506506
f instanceof InstanceFieldOrProperty
507507
or
508508
exists(
509-
FlowSummary::SummarizedCallable callable,
509+
FlowSummaryImpl::Public::SummarizedCallable sc,
510510
FlowSummaryImpl::Public::SummaryComponentStack input
511511
|
512-
callable.propagatesFlow(input, _, _) and
512+
sc.propagatesFlow(input, _, _) and
513513
input.contains(FlowSummary::SummaryComponent::content(f.getContent()))
514514
)
515515
)

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -910,33 +910,6 @@ module Private {
910910
}
911911
}
912912

913-
private class SummarizedCallableExternal extends SummarizedCallable {
914-
SummarizedCallableExternal() { summaryElement(this, _, _, _, _) }
915-
916-
private predicate relevantSummaryElement(AccessPath inSpec, AccessPath outSpec, string kind) {
917-
summaryElement(this, inSpec, outSpec, kind, false)
918-
or
919-
summaryElement(this, inSpec, outSpec, kind, true) and
920-
not summaryElement(this, _, _, _, false)
921-
}
922-
923-
override predicate propagatesFlow(
924-
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue
925-
) {
926-
exists(AccessPath inSpec, AccessPath outSpec, string kind |
927-
this.relevantSummaryElement(inSpec, outSpec, kind) and
928-
interpretSpec(inSpec, input) and
929-
interpretSpec(outSpec, output)
930-
|
931-
kind = "value" and preservesValue = true
932-
or
933-
kind = "taint" and preservesValue = false
934-
)
935-
}
936-
937-
override predicate isAutoGenerated() { summaryElement(this, _, _, _, true) }
938-
}
939-
940913
/** Holds if component `c` of specification `spec` cannot be parsed. */
941914
predicate invalidSpecComponent(AccessPath spec, string c) {
942915
c = spec.getToken(_) and

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,27 @@ private predicate summaryElement0(
9999
private class SummarizedCallableExternal extends FlowSummary::SummarizedCallable {
100100
SummarizedCallableExternal() { summaryElement0(this, _, _, _, _) }
101101

102+
private predicate relevantSummaryElement(AccessPath inSpec, AccessPath outSpec, string kind) {
103+
summaryElement0(this, inSpec, outSpec, kind, false)
104+
or
105+
summaryElement0(this, inSpec, outSpec, kind, true) and
106+
not summaryElement0(this, _, _, _, false)
107+
}
108+
109+
override predicate propagatesFlow(
110+
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue
111+
) {
112+
exists(AccessPath inSpec, AccessPath outSpec, string kind |
113+
this.relevantSummaryElement(inSpec, outSpec, kind) and
114+
External::interpretSpec(inSpec, input) and
115+
External::interpretSpec(outSpec, output)
116+
|
117+
kind = "value" and preservesValue = true
118+
or
119+
kind = "taint" and preservesValue = false
120+
)
121+
}
122+
102123
override predicate isAutoGenerated() { summaryElement0(this, _, _, _, true) }
103124
}
104125

csharp/ql/lib/semmle/code/csharp/frameworks/system/Collections.qll

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import csharp
44
private import semmle.code.csharp.frameworks.System
5-
private import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as Impl
65
private import semmle.code.csharp.dataflow.ExternalFlow
76
private import semmle.code.csharp.dataflow.FlowSummary
87

@@ -48,11 +47,11 @@ private class SystemCollectionIEnumerableFlowModelCsv extends SummaryModelCsv {
4847
}
4948

5049
/** Clear content for Clear methods in all subtypes of `System.Collections.IEnumerable`. */
51-
private class SystemCollectionsIEnumerableClearFlow extends Impl::Public::SummarizedCallable {
50+
private class SystemCollectionsIEnumerableClearFlow extends SummarizedCallable {
5251
SystemCollectionsIEnumerableClearFlow() {
53-
this.asCallable().getDeclaringType().(RefType).getABaseType*() instanceof
52+
this.getDeclaringType().(RefType).getABaseType*() instanceof
5453
SystemCollectionsIEnumerableInterface and
55-
this.asCallable().hasName("Clear")
54+
this.hasName("Clear")
5655
}
5756

5857
override predicate clearsContent(ParameterPosition pos, DataFlow::ContentSet content) {

csharp/ql/lib/semmle/code/csharp/frameworks/system/Text.qll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import csharp
44
private import semmle.code.csharp.frameworks.System
5-
private import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as Impl
65
private import semmle.code.csharp.dataflow.ExternalFlow
76
private import semmle.code.csharp.dataflow.FlowSummary
87

@@ -28,9 +27,9 @@ class SystemTextStringBuilderClass extends SystemTextClass {
2827
}
2928

3029
/** Clear content for `System.Text.StringBuilder.Clear`. */
31-
private class SystemTextStringBuilderClearFlow extends Impl::Public::SummarizedCallable {
30+
private class SystemTextStringBuilderClearFlow extends SummarizedCallable {
3231
SystemTextStringBuilderClearFlow() {
33-
this.asCallable() = any(SystemTextStringBuilderClass s).getAMethod("Clear")
32+
this = any(SystemTextStringBuilderClass s).getAMethod("Clear")
3433
}
3534

3635
override predicate clearsContent(ParameterPosition pos, DataFlow::ContentSet content) {

csharp/ql/src/Telemetry/ExternalApi.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ private import semmle.code.csharp.dataflow.FlowSummary
88
private import semmle.code.csharp.dataflow.internal.DataFlowImplCommon as DataFlowImplCommon
99
private import semmle.code.csharp.dataflow.internal.DataFlowPrivate
1010
private import semmle.code.csharp.dataflow.internal.DataFlowDispatch as DataFlowDispatch
11-
private import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as Impl
1211
private import semmle.code.csharp.dataflow.internal.TaintTrackingPrivate
1312
private import semmle.code.csharp.security.dataflow.flowsources.Remote
1413

@@ -81,7 +80,8 @@ class ExternalApi extends DotNet::Callable {
8180

8281
/** Holds if this API has a supported summary. */
8382
predicate hasSummary() {
84-
exists(Impl::Public::SummarizedCallable sc | sc.asCallable() = this) or
83+
this instanceof SummarizedCallable
84+
or
8585
defaultAdditionalTaintStep(this.getAnInput(), _)
8686
}
8787

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import shared.FlowSummaries
2-
private import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
32

43
private class IncludeAllSummarizedCallable extends IncludeSummarizedCallable {
5-
IncludeAllSummarizedCallable() { this instanceof FlowSummaryImpl::Public::SummarizedCallable }
4+
IncludeAllSummarizedCallable() { this instanceof SummarizedCallable }
65
}
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import shared.FlowSummaries
2-
private import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
32
private import semmle.code.csharp.dataflow.internal.DataFlowPrivate::Csv
43
private import semmle.code.csharp.dataflow.ExternalFlow
54

65
class IncludeFilteredSummarizedCallable extends IncludeSummarizedCallable {
7-
IncludeFilteredSummarizedCallable() {
8-
this instanceof FlowSummaryImpl::Public::SummarizedCallable
9-
}
6+
IncludeFilteredSummarizedCallable() { this instanceof SummarizedCallable }
107

118
/**
129
* Holds if flow is propagated between `input` and `output` and
@@ -18,9 +15,9 @@ class IncludeFilteredSummarizedCallable extends IncludeSummarizedCallable {
1815
) {
1916
this.propagatesFlow(input, output, preservesValue) and
2017
not exists(IncludeSummarizedCallable rsc |
21-
isBaseCallableOrPrototype(rsc.asCallable()) and
18+
isBaseCallableOrPrototype(rsc) and
2219
rsc.propagatesFlow(input, output, preservesValue) and
23-
this.asCallable().(UnboundCallable).overridesOrImplementsUnbound(rsc.asCallable())
20+
this.(UnboundCallable).overridesOrImplementsUnbound(rsc)
2421
)
2522
}
2623
}

0 commit comments

Comments
 (0)