Skip to content

Commit cb578e3

Browse files
committed
Java: Move interpretModelForTest into shared code.
1 parent 7285a8e commit cb578e3

File tree

3 files changed

+138
-6
lines changed

3 files changed

+138
-6
lines changed

java/ql/lib/semmle/code/java/dataflow/ExternalFlow.qll

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,13 @@ private import internal.FlowSummaryImpl
9898
private import internal.FlowSummaryImpl::Public
9999
private import internal.FlowSummaryImpl::Private
100100
private import internal.FlowSummaryImpl::Private::External
101-
private import internal.ExternalFlowExtensions as Extensions
101+
private import internal.ExternalFlowExtensions
102102
private import codeql.mad.ModelValidation as SharedModelVal
103+
private import codeql.mad.static.MaD as SharedMaD
104+
105+
private module MaD = SharedMaD::ModelsAsData<Extensions>;
106+
107+
import MaD
103108

104109
/**
105110
* A class for activating additional model rows.
@@ -214,11 +219,12 @@ predicate summaryModel(
214219
* This predicate should only be used in tests.
215220
*/
216221
predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) {
222+
MaD::interpretModelForTest(madId, model)
223+
or
217224
exists(
218225
string package, string type, boolean subtypes, string name, string signature, string ext,
219226
string output, string kind, string provenance
220227
|
221-
sourceModel(package, type, subtypes, name, signature, ext, output, kind, provenance, madId) or
222228
Extensions::experimentalSourceModel(package, type, subtypes, name, signature, ext, output, kind,
223229
provenance, _, madId)
224230
|
@@ -231,7 +237,6 @@ predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) {
231237
string package, string type, boolean subtypes, string name, string signature, string ext,
232238
string input, string kind, string provenance
233239
|
234-
sinkModel(package, type, subtypes, name, signature, ext, input, kind, provenance, madId) or
235240
Extensions::experimentalSinkModel(package, type, subtypes, name, signature, ext, input, kind,
236241
provenance, _, madId)
237242
|
@@ -244,16 +249,13 @@ predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) {
244249
string package, string type, boolean subtypes, string name, string signature, string ext,
245250
string input, string output, string kind, string provenance
246251
|
247-
summaryModel(package, type, subtypes, name, signature, ext, input, output, kind, provenance,
248-
madId) or
249252
Extensions::experimentalSummaryModel(package, type, subtypes, name, signature, ext, input,
250253
output, kind, provenance, _, madId)
251254
|
252255
model =
253256
"Summary: " + package + "; " + type + "; " + subtypes + "; " + name + "; " + signature + "; " +
254257
ext + "; " + input + "; " + output + "; " + kind + "; " + provenance
255258
)
256-
//TODO: possibly barrier models?
257259
}
258260

259261
/** Holds if a neutral model exists for the given parameters. */

java/ql/lib/semmle/code/java/dataflow/internal/ExternalFlowExtensions.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
overlay[local?]
55
module;
66

7+
private import codeql.mad.static.MaD as SharedMaD
8+
79
/**
810
* Holds if a source model exists for the given parameters.
911
*/
@@ -93,3 +95,7 @@ extensible predicate experimentalSummaryModel(
9395
string input, string output, string kind, string provenance, string filter,
9496
QlBuiltins::ExtensionId madId
9597
);
98+
99+
module Extensions implements SharedMaD::ExtensionsSig {
100+
import ExternalFlowExtensions
101+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
overlay[local?]
2+
module;
3+
4+
signature module ExtensionsSig {
5+
/**
6+
* Holds if a source model exists for the given parameters.
7+
*/
8+
predicate sourceModel(
9+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
10+
string output, string kind, string provenance, QlBuiltins::ExtensionId madId
11+
);
12+
13+
/**
14+
* Holds if a sink model exists for the given parameters.
15+
*/
16+
predicate sinkModel(
17+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
18+
string input, string kind, string provenance, QlBuiltins::ExtensionId madId
19+
);
20+
21+
/**
22+
* Holds if a barrier model exists for the given parameters.
23+
*/
24+
predicate barrierModel(
25+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
26+
string output, string kind, string provenance, QlBuiltins::ExtensionId madId
27+
);
28+
29+
/**
30+
* Holds if a barrier guard model exists for the given parameters.
31+
*/
32+
predicate barrierGuardModel(
33+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
34+
string input, string acceptingvalue, string kind, string provenance,
35+
QlBuiltins::ExtensionId madId
36+
);
37+
38+
/**
39+
* Holds if a summary model exists for the given parameters.
40+
*/
41+
predicate summaryModel(
42+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
43+
string input, string output, string kind, string provenance, QlBuiltins::ExtensionId madId
44+
);
45+
46+
/**
47+
* Holds if a neutral model exists for the given parameters.
48+
*/
49+
predicate neutralModel(
50+
string namespace, string type, string name, string signature, string kind, string provenance
51+
);
52+
}
53+
54+
module ModelsAsData<ExtensionsSig Extensions> {
55+
/**
56+
* Holds if the given extension tuple `madId` should pretty-print as `model`.
57+
*
58+
* Barrier models are included for completeness even though they will not show up in a path.
59+
*
60+
* This predicate should only be used in tests.
61+
*/
62+
predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) {
63+
exists(
64+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
65+
string output, string kind, string provenance
66+
|
67+
Extensions::sourceModel(namespace, type, subtypes, name, signature, ext, output, kind,
68+
provenance, madId)
69+
|
70+
model =
71+
"Source: " + namespace + "; " + type + "; " + subtypes + "; " + name + "; " + signature +
72+
"; " + ext + "; " + output + "; " + kind + "; " + provenance
73+
)
74+
or
75+
exists(
76+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
77+
string input, string kind, string provenance
78+
|
79+
Extensions::sinkModel(namespace, type, subtypes, name, signature, ext, input, kind,
80+
provenance, madId)
81+
|
82+
model =
83+
"Sink: " + namespace + "; " + type + "; " + subtypes + "; " + name + "; " + signature + "; "
84+
+ ext + "; " + input + "; " + kind + "; " + provenance
85+
)
86+
or
87+
exists(
88+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
89+
string output, string kind, string provenance
90+
|
91+
Extensions::barrierModel(namespace, type, subtypes, name, signature, ext, output, kind,
92+
provenance, madId)
93+
|
94+
model =
95+
"Barrier: " + namespace + "; " + type + "; " + subtypes + "; " + name + "; " + signature +
96+
"; " + ext + "; " + output + "; " + kind + "; " + provenance
97+
)
98+
or
99+
exists(
100+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
101+
string input, string acceptingvalue, string kind, string provenance
102+
|
103+
Extensions::barrierGuardModel(namespace, type, subtypes, name, signature, ext, input,
104+
acceptingvalue, kind, provenance, madId)
105+
|
106+
model =
107+
"Barrier Guard: " + namespace + "; " + type + "; " + subtypes + "; " + name + "; " +
108+
signature + "; " + ext + "; " + input + "; " + acceptingvalue + "; " + kind + "; " +
109+
provenance
110+
)
111+
or
112+
exists(
113+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
114+
string input, string output, string kind, string provenance
115+
|
116+
Extensions::summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind,
117+
provenance, madId)
118+
|
119+
model =
120+
"Summary: " + namespace + "; " + type + "; " + subtypes + "; " + name + "; " + signature +
121+
"; " + ext + "; " + input + "; " + output + "; " + kind + "; " + provenance
122+
)
123+
}
124+
}

0 commit comments

Comments
 (0)