Skip to content

Commit b578fcb

Browse files
michaelnebelhvitved
authored andcommitted
C#: Use the external SummarizedCallable implementation.
1 parent 4f72977 commit b578fcb

File tree

6 files changed

+25
-19
lines changed

6 files changed

+25
-19
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ abstract class SummarizedCallable extends DotNet::Callable {
153153
*/
154154
pragma[nomagic]
155155
predicate clearsContent(ParameterPosition pos, DataFlow::ContentSet content) { none() }
156+
157+
/**
158+
* Holds if the summary is auto generated.
159+
*/
160+
predicate isAutoGenerated() { none() }
156161
}
157162

158163
private class SummarizedCallableAdapter extends Impl::Public::SummarizedCallable {
@@ -169,6 +174,8 @@ private class SummarizedCallableAdapter extends Impl::Public::SummarizedCallable
169174
final override predicate clearsContent(ParameterPosition pos, DataFlow::ContentSet content) {
170175
sc.clearsContent(pos, content)
171176
}
177+
178+
final override predicate isAutoGenerated() { sc.isAutoGenerated() }
172179
}
173180

174181
private predicate recordConstructorFlow(Constructor c, int i, Property p) {
@@ -179,25 +186,23 @@ private predicate recordConstructorFlow(Constructor c, int i, Property p) {
179186
)
180187
}
181188

182-
private class RecordConstructorFlow extends Impl::Public::SummarizedCallable {
183-
RecordConstructorFlow() { recordConstructorFlow(this.asCallable(), _, _) }
189+
private class RecordConstructorFlow extends SummarizedCallable {
190+
RecordConstructorFlow() { recordConstructorFlow(this, _, _) }
184191

185192
override predicate propagatesFlow(
186193
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue
187194
) {
188195
exists(int i, Property p |
189-
recordConstructorFlow(this.asCallable(), i, p) and
196+
recordConstructorFlow(this, i, p) and
190197
input = SummaryComponentStack::argument(i) and
191198
output = SummaryComponentStack::propertyOf(p, SummaryComponentStack::return()) and
192199
preservesValue = true
193200
)
194201
}
195202
}
196203

197-
private class SummarizedCallableDefaultClearsContent extends Impl::Public::SummarizedCallable {
198-
SummarizedCallableDefaultClearsContent() {
199-
this instanceof Impl::Public::SummarizedCallable or none()
200-
}
204+
private class SummarizedCallableDefaultClearsContent extends SummarizedCallable {
205+
SummarizedCallableDefaultClearsContent() { this instanceof SummarizedCallable or none() }
201206

202207
// By default, we assume that all stores into arguments are definite
203208
override predicate clearsContent(ParameterPosition pos, DataFlow::ContentSet content) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private predicate summarizedCallable(DataFlowCallable c) {
2929
*/
3030
DotNet::Callable getCallableForDataFlow(DotNet::Callable c) {
3131
exists(DotNet::Callable unboundDecl | unboundDecl = c.getUnboundDeclaration() |
32-
summarizedCallable(TSummarizedCallable(unboundDecl)) and
32+
summarizedCallable(TDotNetCallable(unboundDecl)) and
3333
result = unboundDecl
3434
or
3535
result.hasBody() and

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ private import FlowSummaryImplSpecific
1010
private import DataFlowImplSpecific::Private
1111
private import DataFlowImplSpecific::Public
1212
private import DataFlowImplCommon
13+
private import semmle.code.csharp.dataflow.FlowSummary as FlowSummary
1314

1415
/** Provides classes and predicates for defining flow summaries. */
1516
module Public {
@@ -1069,7 +1070,7 @@ module Private {
10691070
/** Provides a query predicate for outputting a set of relevant flow summaries. */
10701071
module TestOutput {
10711072
/** A flow summary to include in the `summary/3` query predicate. */
1072-
abstract class RelevantSummarizedCallable extends SummarizedCallable {
1073+
abstract class RelevantSummarizedCallable extends FlowSummary::SummarizedCallable {
10731074
/** Gets the string representation of this callable used by `summary/1`. */
10741075
abstract string getCallableCsv();
10751076

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ private predicate summaryElement0(
9898

9999
private class SummarizedCallableExternal extends FlowSummary::SummarizedCallable {
100100
SummarizedCallableExternal() { summaryElement0(this, _, _, _, _) }
101+
102+
override predicate isAutoGenerated() { summaryElement0(this, _, _, _, true) }
101103
}
102104

103105
/**

csharp/ql/lib/semmle/code/csharp/frameworks/EntityFramework.qll

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ private import semmle.code.csharp.frameworks.system.collections.Generic
1010
private import semmle.code.csharp.frameworks.Sql
1111
private import semmle.code.csharp.dataflow.FlowSummary
1212
private import semmle.code.csharp.dataflow.ExternalFlow
13-
private import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as Impl
1413
private import semmle.code.csharp.dataflow.internal.DataFlowPrivate as DataFlowPrivate
1514

1615
/**
@@ -89,7 +88,7 @@ module EntityFramework {
8988
}
9089

9190
/** A flow summary for EntityFramework. */
92-
abstract class EFSummarizedCallable extends Impl::Public::SummarizedCallable { }
91+
abstract class EFSummarizedCallable extends SummarizedCallable { }
9392

9493
private class DbSetAddOrUpdateRequiredSummaryComponentStack extends RequiredSummaryComponentStack {
9594
override predicate required(SummaryComponent head, SummaryComponentStack tail) {
@@ -101,7 +100,7 @@ module EntityFramework {
101100
private class DbSetAddOrUpdate extends EFSummarizedCallable {
102101
private boolean range;
103102

104-
DbSetAddOrUpdate() { this.asCallable() = any(DbSet c).getAnAddOrUpdateMethod(range) }
103+
DbSetAddOrUpdate() { this = any(DbSet c).getAnAddOrUpdateMethod(range) }
105104

106105
override predicate propagatesFlow(
107106
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue
@@ -174,8 +173,8 @@ module EntityFramework {
174173
private class RawSqlStringConstructorSummarizedCallable extends EFSummarizedCallable {
175174
RawSqlStringConstructorSummarizedCallable() {
176175
exists(RawSqlStringStruct s |
177-
this.asCallable() = s.getAConstructor() and
178-
this.asCallable().getNumberOfParameters() > 0
176+
this = s.getAConstructor() and
177+
this.getNumberOfParameters() > 0
179178
)
180179
}
181180

@@ -190,7 +189,7 @@ module EntityFramework {
190189

191190
private class RawSqlStringConversionSummarizedCallable extends EFSummarizedCallable {
192191
RawSqlStringConversionSummarizedCallable() {
193-
exists(RawSqlStringStruct s | this.asCallable() = s.getAConversionTo())
192+
exists(RawSqlStringStruct s | this = s.getAConversionTo())
194193
}
195194

196195
override predicate propagatesFlow(
@@ -449,7 +448,7 @@ module EntityFramework {
449448
private class DbContextSaveChanges extends EFSummarizedCallable {
450449
private DbContextClass c;
451450

452-
DbContextSaveChanges() { this.asCallable() = c.getASaveChanges() }
451+
DbContextSaveChanges() { this = c.getASaveChanges() }
453452

454453
pragma[noinline]
455454
private predicate input(SummaryComponentStack input, Property mapped) {

csharp/ql/test/shared/FlowSummaries.qll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ private import semmle.code.csharp.dataflow.internal.DataFlowPrivate
44

55
abstract class IncludeSummarizedCallable extends RelevantSummarizedCallable {
66
IncludeSummarizedCallable() {
7-
[this.asCallable().(Modifiable), this.asCallable().(Accessor).getDeclaration()]
8-
.isEffectivelyPublic()
7+
[this.(Modifiable), this.(Accessor).getDeclaration()].isEffectivelyPublic()
98
}
109

1110
/** Gets a string representing the callable in semi-colon separated format for use in flow summaries. */
12-
final override string getCallableCsv() { result = Csv::asPartialModel(this.asCallable()) }
11+
final override string getCallableCsv() { result = Csv::asPartialModel(this) }
1312
}

0 commit comments

Comments
 (0)