Skip to content

Commit db4caa2

Browse files
committed
Rust: add Dataflow::BarrierGuard module
1 parent 1b34d4c commit db4caa2

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

rust/ql/lib/codeql/rust/dataflow/DataFlow.qll

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ private import rust
77
private import codeql.dataflow.DataFlow
88
private import internal.DataFlowImpl as DataFlowImpl
99
private import DataFlowImpl::Node as Node
10+
private import codeql.rust.controlflow.ControlFlowGraph as Cfg
11+
private import codeql.rust.controlflow.CfgNodes as CfgNodes
1012

1113
/**
1214
* Provides classes for performing local (intra-procedural) and global
@@ -15,6 +17,8 @@ private import DataFlowImpl::Node as Node
1517
module DataFlow {
1618
final class Node = Node::NodePublic;
1719

20+
final class ExprNode = Node::ExprNode;
21+
1822
/**
1923
* The value of a parameter at function entry, viewed as a node in a data
2024
* flow graph.
@@ -41,4 +45,31 @@ module DataFlow {
4145
predicate localFlow(Node::Node source, Node::Node sink) { localFlowStep*(source, sink) }
4246

4347
import DataFlowMake<Location, DataFlowImpl::RustDataFlow>
48+
49+
/**
50+
* Holds if the guard `g` validates the expression `e` upon evaluating to `v`.
51+
*
52+
* The expression `e` is expected to be a syntactic part of the guard `g`.
53+
* For example, the guard `g` might be a call `isSafe(x)` and the expression `e`
54+
* the argument `x`.
55+
*/
56+
signature predicate guardChecksSig(CfgNodes::AstCfgNode g, Cfg::CfgNode e, boolean branch);
57+
58+
/**
59+
* Provides a set of barrier nodes for a guard that validates an expression.
60+
*
61+
* This is expected to be used in `isBarrier`/`isSanitizer` definitions
62+
* in data flow and taint tracking.
63+
*/
64+
module BarrierGuard<guardChecksSig/3 guardChecks> {
65+
private import internal.DataFlowImpl::SsaFlow as SsaFlow
66+
private import internal.SsaImpl as SsaImpl
67+
68+
/** Gets a node that is safely guarded by the given guard check. */
69+
pragma[nomagic]
70+
Node getABarrierNode() {
71+
SsaFlow::asNode(result) =
72+
SsaImpl::DataFlowIntegration::BarrierGuard<guardChecks/3>::getABarrierNode()
73+
}
74+
}
4475
}

0 commit comments

Comments
 (0)