Skip to content

Commit 7512d81

Browse files
authored
Merge pull request github#12484 from geoffw0/summarydetail
Swift: Update swift/summary/summary-statistics to DataFlow::ConfigSig
2 parents 9a5dbd0 + 7bd0f53 commit 7512d81

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,24 @@ import codeql.swift.dataflow.TaintTracking
1515
/**
1616
* A taint configuration for tainted data reaching any node.
1717
*/
18-
class TaintReachConfig extends TaintTracking::Configuration {
19-
TaintReachConfig() { this = "TaintReachConfig" }
18+
module TaintReachConfig implements DataFlow::ConfigSig {
19+
predicate isSource(DataFlow::Node node) { node instanceof FlowSource }
2020

21-
override predicate isSource(DataFlow::Node node) { node instanceof FlowSource }
22-
23-
override predicate isSink(DataFlow::Node node) { any() }
21+
predicate isSink(DataFlow::Node node) { any() }
2422
}
2523

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-
)
32-
}
24+
module TaintReachFlow = TaintTracking::Make<TaintReachConfig>;
25+
26+
/**
27+
* Gets the total number of dataflow nodes that taint reaches (from any source).
28+
*/
29+
int taintedNodesCount() { result = count(DataFlow::Node n | TaintReachFlow::hasFlowTo(n)) }
30+
31+
/**
32+
* Gets the proportion of dataflow nodes that taint reaches (from any source),
33+
* expressed as a count per million nodes.
34+
*/
35+
float taintReach() { result = (taintedNodesCount() * 1000000.0) / count(DataFlow::Node n) }
3336

3437
predicate statistic(string what, string value) {
3538
what = "Files" and value = count(File f).toString()
@@ -42,6 +45,10 @@ predicate statistic(string what, string value) {
4245
or
4346
what = "Sensitive expressions" and value = count(SensitiveExpr e).toString()
4447
or
48+
what = "Dataflow nodes (total)" and value = count(DataFlow::Node n).toString()
49+
or
50+
what = "Dataflow nodes (tainted)" and value = taintedNodesCount().toString()
51+
or
4552
what = "Taint reach (per million nodes)" and value = taintReach().toString()
4653
}
4754

0 commit comments

Comments
 (0)