Skip to content

Commit 64ac52e

Browse files
committed
C#: Only lift summary models in the model generator.
1 parent 4a98436 commit 64ac52e

File tree

4 files changed

+34
-25
lines changed

4 files changed

+34
-25
lines changed

csharp/ql/src/utils/modelgenerator/internal/CaptureModels.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class DataFlowSourceTargetApi = SourceTargetApi;
3838
class DataFlowSinkTargetApi = SinkTargetApi;
3939

4040
private module ModelPrintingInput implements ModelPrintingSig {
41-
class Api = TargetApiBase;
41+
class SummaryApi = DataFlowSummaryTargetApi;
42+
43+
class SourceOrSinkApi = SourceOrSinkTargetApi;
4244

4345
string getProvenance() { result = "df-generated" }
4446
}

csharp/ql/src/utils/modelgenerator/internal/CaptureModelsSpecific.qll

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,38 +112,41 @@ predicate isUninterestingForDataFlowModels(CS::Callable api) { isHigherOrder(api
112112
predicate isUninterestingForTypeBasedFlowModels(CS::Callable api) { none() }
113113

114114
/**
115-
* A class of callables that are potentially relevant for generating summary and
116-
* neutral models.
115+
* A class of callables that are potentially relevant for generating source or
116+
* sink models.
117117
*/
118-
class SummaryTargetApi extends TargetApiBase {
119-
SummaryTargetApi() { not hasManualSummaryModel(this.lift()) }
118+
class SourceOrSinkTargetApi extends Callable {
119+
SourceOrSinkTargetApi() { relevant(this) }
120120
}
121121

122122
/**
123123
* A class of callables that are potentially relevant for generating sink models.
124124
*/
125-
class SinkTargetApi extends TargetApiBase {
126-
SinkTargetApi() { not hasManualSinkModel(this.lift()) }
125+
class SinkTargetApi extends SourceOrSinkTargetApi {
126+
SinkTargetApi() { not hasManualSinkModel(this) }
127127
}
128128

129129
/**
130130
* A class of callables that are potentially relevant for generating source models.
131131
*/
132-
class SourceTargetApi extends TargetApiBase {
133-
SourceTargetApi() { not hasManualSourceModel(this.lift()) }
132+
class SourceTargetApi extends SourceOrSinkTargetApi {
133+
SourceTargetApi() { not hasManualSourceModel(this) }
134134
}
135135

136136
/**
137-
* A class of callables that are potentially relevant for generating summary, source, sink
138-
* and neutral models.
137+
* A class of callables that are potentially relevant for generating summary or
138+
* neutral models.
139139
*
140140
* In the Standard library and 3rd party libraries it is the callables (or callables that have a
141141
* super implementation) that can be called from outside the library itself.
142142
*/
143-
class TargetApiBase extends Callable {
143+
class SummaryTargetApi extends Callable {
144144
private Callable lift;
145145

146-
TargetApiBase() { lift = liftedImpl(this) }
146+
SummaryTargetApi() {
147+
lift = liftedImpl(this) and
148+
not hasManualSummaryModel(lift)
149+
}
147150

148151
/**
149152
* Gets the callable that a model will be lifted to.

csharp/ql/src/utils/modelgenerator/internal/CaptureTypeBasedSummaryModels.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ private predicate output(Callable callable, TypeParameter tp, string output) {
178178
}
179179

180180
private module ModelPrintingInput implements ModelPrintingSig {
181-
class Api = TypeBasedFlowTargetApi;
181+
class SummaryApi = TypeBasedFlowTargetApi;
182+
183+
class SourceOrSinkApi = TypeBasedFlowTargetApi;
182184

183185
string getProvenance() { result = "tb-generated" }
184186
}

shared/mad/codeql/mad/modelgenerator/ModelPrinting.qll

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ module ModelPrintingImpl<ModelPrintingLangSig Lang> {
1919
/**
2020
* The class of APIs relevant for model generation.
2121
*/
22-
class Api extends Lang::Callable {
22+
class SummaryApi extends Lang::Callable {
2323
Lang::Callable lift();
2424
}
2525

26+
class SourceOrSinkApi extends Lang::Callable;
27+
2628
/**
2729
* Gets the string representation of the provenance of the models.
2830
*/
@@ -33,9 +35,9 @@ module ModelPrintingImpl<ModelPrintingLangSig Lang> {
3335
/**
3436
* Computes the first 6 columns for MaD rows used for summaries, sources and sinks.
3537
*/
36-
private string asPartialModel(Printing::Api api) {
38+
private string asPartialModel(Lang::Callable api) {
3739
exists(string container, string type, string extensible, string name, string parameters |
38-
Lang::partialModel(api.lift(), container, type, extensible, name, parameters) and
40+
Lang::partialModel(api, container, type, extensible, name, parameters) and
3941
result =
4042
container + ";" //
4143
+ type + ";" //
@@ -49,7 +51,7 @@ module ModelPrintingImpl<ModelPrintingLangSig Lang> {
4951
/**
5052
* Computes the first 4 columns for neutral MaD rows.
5153
*/
52-
private string asPartialNeutralModel(Printing::Api api) {
54+
private string asPartialNeutralModel(Printing::SummaryApi api) {
5355
exists(string container, string type, string name, string parameters |
5456
Lang::partialModel(api, container, type, _, name, parameters) and
5557
result =
@@ -64,15 +66,15 @@ module ModelPrintingImpl<ModelPrintingLangSig Lang> {
6466
* Gets the summary model for `api` with `input`, `output` and `kind`.
6567
*/
6668
bindingset[input, output, kind]
67-
private string asSummaryModel(Printing::Api api, string input, string output, string kind) {
69+
private string asSummaryModel(Printing::SummaryApi api, string input, string output, string kind) {
6870
result =
69-
asPartialModel(api) + input + ";" //
71+
asPartialModel(api.lift()) + input + ";" //
7072
+ output + ";" //
7173
+ kind + ";" //
7274
+ Printing::getProvenance()
7375
}
7476

75-
string asNeutralSummaryModel(Printing::Api api) {
77+
string asNeutralSummaryModel(Printing::SummaryApi api) {
7678
result =
7779
asPartialNeutralModel(api) //
7880
+ "summary" + ";" //
@@ -83,23 +85,23 @@ module ModelPrintingImpl<ModelPrintingLangSig Lang> {
8385
* Gets the value summary model for `api` with `input` and `output`.
8486
*/
8587
bindingset[input, output]
86-
string asValueModel(Printing::Api api, string input, string output) {
88+
string asValueModel(Printing::SummaryApi api, string input, string output) {
8789
result = asSummaryModel(api, input, output, "value")
8890
}
8991

9092
/**
9193
* Gets the taint summary model for `api` with `input` and `output`.
9294
*/
9395
bindingset[input, output]
94-
string asTaintModel(Printing::Api api, string input, string output) {
96+
string asTaintModel(Printing::SummaryApi api, string input, string output) {
9597
result = asSummaryModel(api, input, output, "taint")
9698
}
9799

98100
/**
99101
* Gets the sink model for `api` with `input` and `kind`.
100102
*/
101103
bindingset[input, kind]
102-
string asSinkModel(Printing::Api api, string input, string kind) {
104+
string asSinkModel(Printing::SourceOrSinkApi api, string input, string kind) {
103105
result =
104106
asPartialModel(api) + input + ";" //
105107
+ kind + ";" //
@@ -110,7 +112,7 @@ module ModelPrintingImpl<ModelPrintingLangSig Lang> {
110112
* Gets the source model for `api` with `output` and `kind`.
111113
*/
112114
bindingset[output, kind]
113-
string asSourceModel(Printing::Api api, string output, string kind) {
115+
string asSourceModel(Printing::SourceOrSinkApi api, string output, string kind) {
114116
result =
115117
asPartialModel(api) + output + ";" //
116118
+ kind + ";" //

0 commit comments

Comments
 (0)