Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rust/ql/src/queries/summary/Stats.qll
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ predicate taintStats(string key, int value) {
or
key = "Taint reach - nodes tainted" and value = getTaintedNodesCount()
or
key = "Taint reach - total non-summary nodes" and value = getTotalNodesCount()
or
key = "Taint reach - per million nodes" and value = getTaintReach().floor()
or
key = "Taint sinks - query sinks" and value = getQuerySinksCount()
Expand Down
21 changes: 19 additions & 2 deletions rust/ql/src/queries/summary/TaintReach.qll
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import rust
private import codeql.rust.Concepts
private import codeql.rust.dataflow.DataFlow
private import codeql.rust.dataflow.TaintTracking
private import codeql.rust.dataflow.internal.Node

/**
* A taint configuration for taint reach (flow to any node from any modeled source).
Expand All @@ -21,11 +22,27 @@ private module TaintReachFlow = TaintTracking::Global<TaintReachConfig>;

/**
* Gets the total number of data flow nodes that taint reaches (from any source).
*
* We don't include flow summary nodes, as their number is unstable (varies when models
* are added).
*/
int getTaintedNodesCount() { result = count(DataFlow::Node n | TaintReachFlow::flowTo(n)) }
int getTaintedNodesCount() {
result = count(DataFlow::Node n | TaintReachFlow::flowTo(n) and not n instanceof FlowSummaryNode)
}

/**
* Gets the total number of data flow nodes.
*
* We don't include flow summary nodes, as their number is unstable (varies when models
* are added).
*/
int getTotalNodesCount() { result = count(DataFlow::Node n | not n instanceof FlowSummaryNode) }

/**
* Gets the proportion of data flow nodes that taint reaches (from any source),
* expressed as a count per million nodes.
*
* We don't include flow summary nodes, as their number is unstable (varies when models
* are added).
*/
float getTaintReach() { result = (getTaintedNodesCount() * 1000000.0) / count(DataFlow::Node n) }
float getTaintReach() { result = (getTaintedNodesCount() * 1000000.0) / getTotalNodesCount() }