Skip to content

Commit a85f359

Browse files
committed
Java: Move interpretModelForTest into shared code.
1 parent 05a3c31 commit a85f359

File tree

3 files changed

+135
-6
lines changed

3 files changed

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

0 commit comments

Comments
 (0)