Skip to content

Commit 7f06109

Browse files
committed
Swift: Add detail to the swift/summary/summary-statistics query.
1 parent a4c0a03 commit 7f06109

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

swift/ql/src/queries/Summary/SummaryStats.ql

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,19 @@ class TaintReachConfig extends TaintTracking::Configuration {
2323
override predicate isSink(DataFlow::Node node) { any() }
2424
}
2525

26-
float taintReach() {
27-
exists(TaintReachConfig config, int tainted, int total |
28-
tainted = count(DataFlow::Node n | config.hasFlowTo(n)) and
29-
total = count(DataFlow::Node n) and
30-
result = (tainted * 1000000.0) / total
31-
)
26+
/**
27+
* Gets the total number of dataflow nodes that taint reaches (from any source).
28+
*/
29+
int taintedNodesCount() {
30+
exists(TaintReachConfig config | result = count(DataFlow::Node n | config.hasFlowTo(n)))
3231
}
3332

33+
/**
34+
* Gets the proportion of dataflow nodes that taint reaches (from any source),
35+
* expressed as a count per million nodes.
36+
*/
37+
float taintReach() { result = (taintedNodesCount() * 1000000.0) / count(DataFlow::Node n) }
38+
3439
predicate statistic(string what, string value) {
3540
what = "Files" and value = count(File f).toString()
3641
or
@@ -42,6 +47,10 @@ predicate statistic(string what, string value) {
4247
or
4348
what = "Sensitive expressions" and value = count(SensitiveExpr e).toString()
4449
or
50+
what = "Dataflow nodes (total)" and value = count(DataFlow::Node n).toString()
51+
or
52+
what = "Dataflow nodes (tainted)" and value = taintedNodesCount().toString()
53+
or
4554
what = "Taint reach (per million nodes)" and value = taintReach().toString()
4655
}
4756

0 commit comments

Comments
 (0)