Skip to content

Commit ed4819a

Browse files
committed
Rust: Cache defaultAdditionalTaintStep
1 parent 7eb3b40 commit ed4819a

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,9 +1101,11 @@ import MakeImpl<Location, RustDataFlow>
11011101
/** A collection of cached types and predicates to be evaluated in the same stage. */
11021102
cached
11031103
private module Cached {
1104+
private import codeql.rust.internal.CachedStages
1105+
11041106
cached
11051107
newtype TNode =
1106-
TExprNode(ExprCfgNode n) or
1108+
TExprNode(ExprCfgNode n) { Stages::DataFlowStage::ref() } or
11071109
TSourceParameterNode(ParamBaseCfgNode p) or
11081110
TPatNode(PatCfgNode p) or
11091111
TExprPostUpdateNode(ExprCfgNode e) {

rust/ql/lib/codeql/rust/dataflow/internal/TaintTrackingImpl.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ private import codeql.rust.controlflow.CfgNodes
44
private import codeql.rust.dataflow.FlowSummary
55
private import DataFlowImpl
66
private import FlowSummaryImpl as FlowSummaryImpl
7+
private import codeql.rust.internal.CachedStages
78

89
module RustTaintTracking implements InputSig<Location, RustDataFlow> {
910
predicate defaultTaintSanitizer(Node::Node node) { none() }
@@ -12,7 +13,9 @@ module RustTaintTracking implements InputSig<Location, RustDataFlow> {
1213
* Holds if the additional step from `pred` to `succ` should be included in all
1314
* global taint flow configurations.
1415
*/
16+
cached
1517
predicate defaultAdditionalTaintStep(Node::Node pred, Node::Node succ, string model) {
18+
Stages::DataFlowStage::ref() and
1619
model = "" and
1720
(
1821
exists(BinaryExprCfgNode binary |

rust/ql/lib/codeql/rust/elements/internal/ArrayExprImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module Impl {
2222
* ```
2323
*/
2424
class ArrayExpr extends Generated::ArrayExpr {
25-
cached
25+
pragma[nomagic]
2626
private Raw::ArrayExprInternal getUnderlyingEntity() {
2727
this = Synth::TArrayListExpr(result) or this = Synth::TArrayRepeatExpr(result)
2828
}

rust/ql/lib/codeql/rust/internal/CachedStages.qll

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ module Stages {
3535
*/
3636
cached
3737
module AstStage {
38-
private import codeql.rust.controlflow.internal.Splitting
39-
private import codeql.rust.controlflow.internal.SuccessorType
40-
private import codeql.rust.controlflow.internal.ControlFlowGraphImpl
41-
4238
/**
4339
* Always holds.
4440
* Ensures that a predicate is evaluated as part of the AST stage.
@@ -98,4 +94,34 @@ module Stages {
9894
exists(CallExprCfgNode n | exists(n.getFunction()))
9995
}
10096
}
97+
98+
/**
99+
* The data flow stage.
100+
*/
101+
cached
102+
module DataFlowStage {
103+
private import codeql.rust.dataflow.internal.DataFlowImpl
104+
private import codeql.rust.dataflow.internal.TaintTrackingImpl
105+
106+
/**
107+
* Always holds.
108+
* Ensures that a predicate is evaluated as part of the data flow stage.
109+
*/
110+
cached
111+
predicate ref() { 1 = 1 }
112+
113+
/**
114+
* DO NOT USE!
115+
*
116+
* Contains references to each predicate that use the above `ref` predicate.
117+
*/
118+
cached
119+
predicate backref() {
120+
1 = 1
121+
or
122+
exists(Node n)
123+
or
124+
RustTaintTracking::defaultAdditionalTaintStep(_, _, _)
125+
}
126+
}
101127
}

0 commit comments

Comments
 (0)