Skip to content

Commit e262438

Browse files
committed
C++: Use shared model coverage code.
1 parent 0725251 commit e262438

File tree

2 files changed

+6
-57
lines changed

2 files changed

+6
-57
lines changed

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

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ private module MadInput implements SharedMaD::InputSig {
213213
provenance = "manual" and
214214
model = ""
215215
}
216+
217+
string namespaceSegmentSeparator() { result = "::" }
216218
}
217219

218220
private module MaD = SharedMaD::ModelsAsData<Extensions, MadInput>;
@@ -247,62 +249,6 @@ predicate summaryModel(
247249
)
248250
}
249251

250-
private predicate relevantNamespace(string namespace) {
251-
sourceModel(namespace, _, _, _, _, _, _, _, _, _) or
252-
sinkModel(namespace, _, _, _, _, _, _, _, _, _) or
253-
summaryModel(namespace, _, _, _, _, _, _, _, _, _, _)
254-
}
255-
256-
private predicate namespaceLink(string shortns, string longns) {
257-
relevantNamespace(shortns) and
258-
relevantNamespace(longns) and
259-
longns.prefix(longns.indexOf("::")) = shortns
260-
}
261-
262-
private predicate canonicalNamespace(string namespace) {
263-
relevantNamespace(namespace) and not namespaceLink(_, namespace)
264-
}
265-
266-
private predicate canonicalNamespaceLink(string namespace, string subns) {
267-
canonicalNamespace(namespace) and
268-
(subns = namespace or namespaceLink(namespace, subns))
269-
}
270-
271-
/**
272-
* Holds if MaD framework coverage of `namespace` is `n` api endpoints of the
273-
* kind `(kind, part)`, and `namespaces` is the number of subnamespaces of
274-
* `namespace` which have MaD framework coverage (including `namespace`
275-
* itself).
276-
*/
277-
predicate modelCoverage(string namespace, int namespaces, string kind, string part, int n) {
278-
namespaces = strictcount(string subns | canonicalNamespaceLink(namespace, subns)) and
279-
(
280-
part = "source" and
281-
n =
282-
strictcount(string subns, string type, boolean subtypes, string name, string signature,
283-
string ext, string output, string provenance, string model |
284-
canonicalNamespaceLink(namespace, subns) and
285-
sourceModel(subns, type, subtypes, name, signature, ext, output, kind, provenance, model)
286-
)
287-
or
288-
part = "sink" and
289-
n =
290-
strictcount(string subns, string type, boolean subtypes, string name, string signature,
291-
string ext, string input, string provenance, string model |
292-
canonicalNamespaceLink(namespace, subns) and
293-
sinkModel(subns, type, subtypes, name, signature, ext, input, kind, provenance, model)
294-
)
295-
or
296-
part = "summary" and
297-
n =
298-
strictcount(string subns, string type, boolean subtypes, string name, string signature,
299-
string ext, string input, string output, string provenance |
300-
canonicalNamespaceLink(namespace, subns) and
301-
summaryModel(subns, type, subtypes, name, signature, ext, input, output, kind, provenance, _)
302-
)
303-
)
304-
}
305-
306252
/** Provides a query predicate to check the CSV data for validation errors. */
307253
module CsvValidation {
308254
private string getInvalidModelInput() {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ signature module InputSig {
8181
) {
8282
none()
8383
}
84+
85+
/** Get the separator used between namespace segments. */
86+
default string namespaceSegmentSeparator() { result = "." }
8487
}
8588

8689
module ModelsAsData<ExtensionsSig Extensions, InputSig Input> {
@@ -214,7 +217,7 @@ module ModelsAsData<ExtensionsSig Extensions, InputSig Input> {
214217
private predicate namespaceLink(string shortns, string longns) {
215218
relevantNamespace(shortns) and
216219
relevantNamespace(longns) and
217-
longns.prefix(longns.indexOf(".")) = shortns
220+
longns.prefix(longns.indexOf(Input::namespaceSegmentSeparator())) = shortns
218221
}
219222

220223
private predicate canonicalNamespace(string namespace) {

0 commit comments

Comments
 (0)