Skip to content

Commit 72ae902

Browse files
authored
Merge pull request github#5371 from aschackmull/java/framework-coverage
Java: Add query for CSV framework coverage.
2 parents 8ff9c98 + 234f62f commit 72ae902

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @name Framework coverage
3+
* @description The number of API endpoints covered by CSV models sorted by
4+
* package and source-, sink-, and summary-kind.
5+
* @kind table
6+
* @id java/meta/framework-coverage
7+
*/
8+
9+
import java
10+
import semmle.code.java.dataflow.ExternalFlow
11+
12+
from string package, int pkgs, string kind, string part, int n
13+
where modelCoverage(package, pkgs, kind, part, n)
14+
select package, pkgs, kind, part, n

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,60 @@ private predicate summaryModel(
372372
)
373373
}
374374

375+
private predicate relevantPackage(string package) {
376+
sourceModel(package, _, _, _, _, _, _, _) or
377+
sinkModel(package, _, _, _, _, _, _, _) or
378+
summaryModel(package, _, _, _, _, _, _, _, _)
379+
}
380+
381+
private predicate packageLink(string shortpkg, string longpkg) {
382+
relevantPackage(shortpkg) and
383+
relevantPackage(longpkg) and
384+
longpkg.prefix(longpkg.indexOf(".")) = shortpkg
385+
}
386+
387+
private predicate canonicalPackage(string package) {
388+
relevantPackage(package) and not packageLink(_, package)
389+
}
390+
391+
private predicate canonicalPkgLink(string package, string subpkg) {
392+
canonicalPackage(package) and
393+
(subpkg = package or packageLink(package, subpkg))
394+
}
395+
396+
/**
397+
* Holds if CSV framework coverage of `package` is `n` api endpoints of the
398+
* kind `(kind, part)`.
399+
*/
400+
predicate modelCoverage(string package, int pkgs, string kind, string part, int n) {
401+
pkgs = strictcount(string subpkg | canonicalPkgLink(package, subpkg)) and
402+
(
403+
part = "source" and
404+
n =
405+
strictcount(string subpkg, string type, boolean subtypes, string name, string signature,
406+
string ext, string output |
407+
canonicalPkgLink(package, subpkg) and
408+
sourceModel(subpkg, type, subtypes, name, signature, ext, output, kind)
409+
)
410+
or
411+
part = "sink" and
412+
n =
413+
strictcount(string subpkg, string type, boolean subtypes, string name, string signature,
414+
string ext, string input |
415+
canonicalPkgLink(package, subpkg) and
416+
sinkModel(subpkg, type, subtypes, name, signature, ext, input, kind)
417+
)
418+
or
419+
part = "summary" and
420+
n =
421+
strictcount(string subpkg, string type, boolean subtypes, string name, string signature,
422+
string ext, string input, string output |
423+
canonicalPkgLink(package, subpkg) and
424+
summaryModel(subpkg, type, subtypes, name, signature, ext, input, output, kind)
425+
)
426+
)
427+
}
428+
375429
/** Provides a query predicate to check the CSV data for validation errors. */
376430
module CsvValidation {
377431
/** Holds if some row in a CSV-based flow model appears to contain typos. */

0 commit comments

Comments
 (0)