@@ -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
3437predicate 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