Skip to content

Commit 9cd16fd

Browse files
committed
Java: Base the model printing on the shared implementation.
1 parent 8630583 commit 9cd16fd

File tree

5 files changed

+26
-115
lines changed

5 files changed

+26
-115
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ class DataFlowTargetApi extends TargetApiSpecific {
3333
DataFlowTargetApi() { not isUninterestingForDataFlowModels(this) }
3434
}
3535

36-
private module Printing implements PrintingSig {
36+
private module ModelPrintingInput implements ModelPrintingSig {
3737
class Api = DataFlowTargetApi;
3838

3939
string getProvenance() { result = "df-generated" }
4040
}
4141

42-
module ModelPrinting = PrintingImpl<Printing>;
42+
module Printing = ModelPrinting<ModelPrintingInput>;
4343

4444
/**
4545
* Holds if `c` is a relevant content kind, where the underlying type is relevant.
@@ -94,7 +94,7 @@ string captureQualifierFlow(TargetApiSpecific api) {
9494
api = returnNodeEnclosingCallable(ret) and
9595
isOwnInstanceAccessNode(ret)
9696
) and
97-
result = ModelPrinting::asValueModel(api, qualifierString(), "ReturnValue")
97+
result = Printing::asValueModel(api, qualifierString(), "ReturnValue")
9898
}
9999

100100
private int accessPathLimit0() { result = 2 }
@@ -202,7 +202,7 @@ string captureThroughFlow(DataFlowTargetApi api) {
202202
input = parameterNodeAsInput(p) and
203203
output = returnNodeExt.getOutput() and
204204
input != output and
205-
result = ModelPrinting::asTaintModel(api, input, output)
205+
result = Printing::asTaintModel(api, input, output)
206206
)
207207
}
208208

@@ -250,7 +250,7 @@ string captureSource(DataFlowTargetApi api) {
250250
ExternalFlow::sourceNode(source, kind) and
251251
api = sink.getEnclosingCallable() and
252252
not irrelevantSourceSinkApi(source.getEnclosingCallable(), api) and
253-
result = ModelPrinting::asSourceModel(api, sink.getOutput(), kind)
253+
result = Printing::asSourceModel(api, sink.getOutput(), kind)
254254
)
255255
}
256256

@@ -291,6 +291,6 @@ string captureSink(DataFlowTargetApi api) {
291291
PropagateToSink::flow(src, sink) and
292292
ExternalFlow::sinkNode(sink, kind) and
293293
api = src.getEnclosingCallable() and
294-
result = ModelPrinting::asSinkModel(api, asInputArgument(src), kind)
294+
result = Printing::asSinkModel(api, asInputArgument(src), kind)
295295
)
296296
}
Lines changed: 7 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,11 @@
1-
private import CaptureModelsSpecific
1+
private import java as J
2+
private import codeql.mad.modelgenerator.ModelPrinting
3+
private import CaptureModelsSpecific as Specific
24

3-
signature module PrintingSig {
4-
/**
5-
* The class of APIs relevant for model generation.
6-
*/
7-
class Api extends TargetApiSpecific;
5+
private module ModelPrintingLang implements ModelPrintingLangSig {
6+
class Callable = J::Callable;
87

9-
/**
10-
* Gets the string representation of the provenance of the models.
11-
*/
12-
string getProvenance();
8+
predicate partialModel = Specific::partialModel/6;
139
}
1410

15-
module PrintingImpl<PrintingSig Printing> {
16-
/**
17-
* Gets the summary model for `api` with `input`, `output` and `kind`.
18-
*/
19-
bindingset[input, output, kind]
20-
private string asSummaryModel(Printing::Api api, string input, string output, string kind) {
21-
result =
22-
asPartialModel(api) + input + ";" //
23-
+ output + ";" //
24-
+ kind + ";" //
25-
+ Printing::getProvenance()
26-
}
27-
28-
string asNeutralSummaryModel(Printing::Api api) {
29-
result =
30-
asPartialNeutralModel(api) //
31-
+ "summary" + ";" //
32-
+ Printing::getProvenance()
33-
}
34-
35-
/**
36-
* Gets the value summary model for `api` with `input` and `output`.
37-
*/
38-
bindingset[input, output]
39-
string asValueModel(Printing::Api api, string input, string output) {
40-
result = asSummaryModel(api, input, output, "value")
41-
}
42-
43-
/**
44-
* Gets the taint summary model for `api` with `input` and `output`.
45-
*/
46-
bindingset[input, output]
47-
string asTaintModel(Printing::Api api, string input, string output) {
48-
result = asSummaryModel(api, input, output, "taint")
49-
}
50-
51-
/**
52-
* Gets the sink model for `api` with `input` and `kind`.
53-
*/
54-
bindingset[input, kind]
55-
string asSinkModel(Printing::Api api, string input, string kind) {
56-
result =
57-
asPartialModel(api) + input + ";" //
58-
+ kind + ";" //
59-
+ Printing::getProvenance()
60-
}
61-
62-
/**
63-
* Gets the source model for `api` with `output` and `kind`.
64-
*/
65-
bindingset[output, kind]
66-
string asSourceModel(Printing::Api api, string output, string kind) {
67-
result =
68-
asPartialModel(api) + output + ";" //
69-
+ kind + ";" //
70-
+ Printing::getProvenance()
71-
}
72-
}
11+
import ModelPrintingImpl<ModelPrintingLang>

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

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -110,53 +110,25 @@ private string isExtensible(Callable c) {
110110
}
111111

112112
/**
113-
* Returns the appropriate type name for the model.
113+
* Holds if the callable `c` is in package `package`
114+
* and is a member of `type`.
114115
*/
115-
private string typeAsModel(Callable c) {
116-
exists(RefType type | type = c.getDeclaringType() |
117-
result =
118-
type.getCompilationUnit().getPackage().getName() + ";" +
119-
type.getErasure().(J::RefType).nestedName()
116+
private predicate qualifiedName(Callable c, string package, string type) {
117+
exists(RefType t | t = c.getDeclaringType() |
118+
package = t.getCompilationUnit().getPackage().getName() and
119+
type = t.getErasure().(J::RefType).nestedName()
120120
)
121121
}
122122

123-
private predicate partialModel(
124-
Callable api, string type, string extensible, string name, string parameters
123+
predicate partialModel(
124+
Callable api, string package, string type, string extensible, string name, string parameters
125125
) {
126-
type = typeAsModel(api) and
126+
qualifiedName(api, package, type) and
127127
extensible = isExtensible(api) and
128128
name = api.getName() and
129129
parameters = ExternalFlow::paramsString(api)
130130
}
131131

132-
/**
133-
* Computes the first 6 columns for MaD rows.
134-
*/
135-
string asPartialModel(TargetApiSpecific api) {
136-
exists(string type, string extensible, string name, string parameters |
137-
partialModel(api.lift(), type, extensible, name, parameters) and
138-
result =
139-
type + ";" //
140-
+ extensible + ";" //
141-
+ name + ";" //
142-
+ parameters + ";" //
143-
+ /* ext + */ ";" //
144-
)
145-
}
146-
147-
/**
148-
* Computes the first 4 columns for neutral MaD rows.
149-
*/
150-
string asPartialNeutralModel(TargetApiSpecific api) {
151-
exists(string type, string name, string parameters |
152-
partialModel(api, type, _, name, parameters) and
153-
result =
154-
type + ";" //
155-
+ name + ";" //
156-
+ parameters + ";" //
157-
)
158-
}
159-
160132
predicate isPrimitiveTypeUsedForBulkData(J::Type t) {
161133
t.hasName(["byte", "char", "Byte", "Character"])
162134
}

java/ql/src/utils/modelgenerator/internal/CaptureSummaryFlowQuery.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,5 @@ string captureFlow(DataFlowTargetApi api) {
8080
string captureNoFlow(DataFlowTargetApi api) {
8181
not exists(DataFlowTargetApi api0 | exists(captureFlow(api0)) and api0.lift() = api.lift()) and
8282
api.isRelevant() and
83-
result = ModelPrinting::asNeutralSummaryModel(api)
83+
result = Printing::asNeutralSummaryModel(api)
8484
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,13 @@ private predicate output(Callable callable, TypeVariable tv, string output) {
283283
functionalSink(callable, tv, output)
284284
}
285285

286-
module Printing implements PrintingSig {
286+
module ModelPrintingInput implements ModelPrintingSig {
287287
class Api = TypeBasedFlowTargetApi;
288288

289289
string getProvenance() { result = "tb-generated" }
290290
}
291291

292-
private module ModelPrinting = PrintingImpl<Printing>;
292+
private module Printing = ModelPrinting<ModelPrintingInput>;
293293

294294
/**
295295
* A class of callables that are relevant generating summaries for based
@@ -327,7 +327,7 @@ class TypeBasedFlowTargetApi extends Specific::TargetApiSpecific {
327327
output(this, tv, output) and
328328
input != output
329329
|
330-
result = ModelPrinting::asValueModel(this, input, output)
330+
result = Printing::asValueModel(this, input, output)
331331
)
332332
}
333333
}

0 commit comments

Comments
 (0)