Skip to content

Commit 3b334ea

Browse files
committed
Java/C#: Share model coverage code.
1 parent 0915db4 commit 3b334ea

File tree

3 files changed

+59
-113
lines changed

3 files changed

+59
-113
lines changed

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

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -107,62 +107,6 @@ private module MaD = SharedMaD::ModelsAsData<Extensions>;
107107

108108
import MaD
109109

110-
private predicate relevantNamespace(string namespace) {
111-
sourceModel(namespace, _, _, _, _, _, _, _, _, _) or
112-
sinkModel(namespace, _, _, _, _, _, _, _, _, _) or
113-
summaryModel(namespace, _, _, _, _, _, _, _, _, _, _)
114-
}
115-
116-
private predicate namespaceLink(string shortns, string longns) {
117-
relevantNamespace(shortns) and
118-
relevantNamespace(longns) and
119-
longns.prefix(longns.indexOf(".")) = shortns
120-
}
121-
122-
private predicate canonicalNamespace(string namespace) {
123-
relevantNamespace(namespace) and not namespaceLink(_, namespace)
124-
}
125-
126-
private predicate canonicalNamespaceLink(string namespace, string subns) {
127-
canonicalNamespace(namespace) and
128-
(subns = namespace or namespaceLink(namespace, subns))
129-
}
130-
131-
/**
132-
* Holds if MaD framework coverage of `namespace` is `n` api endpoints of the
133-
* kind `(kind, part)`, and `namespaces` is the number of subnamespaces of
134-
* `namespace` which have MaD framework coverage (including `namespace`
135-
* itself).
136-
*/
137-
predicate modelCoverage(string namespace, int namespaces, string kind, string part, int n) {
138-
namespaces = strictcount(string subns | canonicalNamespaceLink(namespace, subns)) and
139-
(
140-
part = "source" and
141-
n =
142-
strictcount(string subns, string type, boolean subtypes, string name, string signature,
143-
string ext, string output, string provenance |
144-
canonicalNamespaceLink(namespace, subns) and
145-
sourceModel(subns, type, subtypes, name, signature, ext, output, kind, provenance, _)
146-
)
147-
or
148-
part = "sink" and
149-
n =
150-
strictcount(string subns, string type, boolean subtypes, string name, string signature,
151-
string ext, string input, string provenance |
152-
canonicalNamespaceLink(namespace, subns) and
153-
sinkModel(subns, type, subtypes, name, signature, ext, input, kind, provenance, _)
154-
)
155-
or
156-
part = "summary" and
157-
n =
158-
strictcount(string subns, string type, boolean subtypes, string name, string signature,
159-
string ext, string input, string output, string provenance |
160-
canonicalNamespaceLink(namespace, subns) and
161-
summaryModel(subns, type, subtypes, name, signature, ext, input, output, kind, provenance, _)
162-
)
163-
)
164-
}
165-
166110
/** Provides a query predicate to check the MaD models for validation errors. */
167111
module ModelValidation {
168112
private predicate getRelevantAccessPath(string path) {

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

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -261,63 +261,6 @@ predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) {
261261
/** Holds if a neutral model exists for the given parameters. */
262262
predicate neutralModel = Extensions::neutralModel/6;
263263

264-
private predicate relevantPackage(string package) {
265-
sourceModel(package, _, _, _, _, _, _, _, _, _) or
266-
sinkModel(package, _, _, _, _, _, _, _, _, _) or
267-
summaryModel(package, _, _, _, _, _, _, _, _, _, _)
268-
}
269-
270-
private predicate packageLink(string shortpkg, string longpkg) {
271-
relevantPackage(shortpkg) and
272-
relevantPackage(longpkg) and
273-
longpkg.prefix(longpkg.indexOf(".")) = shortpkg
274-
}
275-
276-
private predicate canonicalPackage(string package) {
277-
relevantPackage(package) and not packageLink(_, package)
278-
}
279-
280-
private predicate canonicalPkgLink(string package, string subpkg) {
281-
canonicalPackage(package) and
282-
(subpkg = package or packageLink(package, subpkg))
283-
}
284-
285-
/**
286-
* Holds if MaD framework coverage of `package` is `n` api endpoints of the
287-
* kind `(kind, part)`, and `pkgs` is the number of subpackages of `package`
288-
* which have MaD framework coverage (including `package` itself).
289-
*/
290-
predicate modelCoverage(string package, int pkgs, string kind, string part, int n) {
291-
pkgs = strictcount(string subpkg | canonicalPkgLink(package, subpkg)) and
292-
(
293-
part = "source" and
294-
n =
295-
strictcount(string subpkg, string type, boolean subtypes, string name, string signature,
296-
string ext, string output, string provenance |
297-
canonicalPkgLink(package, subpkg) and
298-
sourceModel(subpkg, type, subtypes, name, signature, ext, output, kind, provenance, _)
299-
)
300-
or
301-
part = "sink" and
302-
n =
303-
strictcount(string subpkg, string type, boolean subtypes, string name, string signature,
304-
string ext, string input, string provenance |
305-
canonicalPkgLink(package, subpkg) and
306-
sinkModel(subpkg, type, subtypes, name, signature, ext, input, kind, provenance, _)
307-
)
308-
or
309-
part = "summary" and
310-
n =
311-
strictcount(string subpkg, string type, boolean subtypes, string name, string signature,
312-
string ext, string input, string output, string provenance |
313-
canonicalPkgLink(package, subpkg) and
314-
summaryModel(subpkg, type, subtypes, name, signature, ext, input, output, kind, provenance,
315-
_)
316-
)
317-
// TODO: possibly barrier models?
318-
)
319-
}
320-
321264
/** Provides a query predicate to check the MaD models for validation errors. */
322265
module ModelValidation {
323266
private import codeql.dataflow.internal.AccessPathSyntax as AccessPathSyntax

shared/mad/codeql/mad/static/MaD.qll

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,63 @@ module ModelsAsData<ExtensionsSig Extensions> {
121121
"; " + ext + "; " + input + "; " + output + "; " + kind + "; " + provenance
122122
)
123123
}
124+
125+
private predicate relevantNamespace(string namespace) {
126+
Extensions::sourceModel(namespace, _, _, _, _, _, _, _, _, _) or
127+
Extensions::sinkModel(namespace, _, _, _, _, _, _, _, _, _) or
128+
Extensions::summaryModel(namespace, _, _, _, _, _, _, _, _, _, _)
129+
}
130+
131+
private predicate namespaceLink(string shortns, string longns) {
132+
relevantNamespace(shortns) and
133+
relevantNamespace(longns) and
134+
longns.prefix(longns.indexOf(".")) = shortns
135+
}
136+
137+
private predicate canonicalNamespace(string namespace) {
138+
relevantNamespace(namespace) and not namespaceLink(_, namespace)
139+
}
140+
141+
private predicate canonicalNamespaceLink(string namespace, string subns) {
142+
canonicalNamespace(namespace) and
143+
(subns = namespace or namespaceLink(namespace, subns))
144+
}
145+
146+
/**
147+
* Holds if MaD framework coverage of `namespace` is `n` api endpoints of the
148+
* kind `(kind, part)`, and `namespaces` is the number of subnamespaces of
149+
* `namespace` which have MaD framework coverage (including `namespace`
150+
* itself).
151+
*/
152+
predicate modelCoverage(string namespace, int namespaces, string kind, string part, int n) {
153+
namespaces = strictcount(string subns | canonicalNamespaceLink(namespace, subns)) and
154+
(
155+
part = "source" and
156+
n =
157+
strictcount(string subns, string type, boolean subtypes, string name, string signature,
158+
string ext, string output, string provenance |
159+
canonicalNamespaceLink(namespace, subns) and
160+
Extensions::sourceModel(subns, type, subtypes, name, signature, ext, output, kind,
161+
provenance, _)
162+
)
163+
or
164+
part = "sink" and
165+
n =
166+
strictcount(string subns, string type, boolean subtypes, string name, string signature,
167+
string ext, string input, string provenance |
168+
canonicalNamespaceLink(namespace, subns) and
169+
Extensions::sinkModel(subns, type, subtypes, name, signature, ext, input, kind,
170+
provenance, _)
171+
)
172+
or
173+
part = "summary" and
174+
n =
175+
strictcount(string subns, string type, boolean subtypes, string name, string signature,
176+
string ext, string input, string output, string provenance |
177+
canonicalNamespaceLink(namespace, subns) and
178+
Extensions::summaryModel(subns, type, subtypes, name, signature, ext, input, output, kind,
179+
provenance, _)
180+
)
181+
)
182+
}
124183
}

0 commit comments

Comments
 (0)