Skip to content

Commit f45eca7

Browse files
committed
Address review comments
1 parent 72028c0 commit f45eca7

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,20 @@ private ExprCfgNode getALastEvalNode(ExprCfgNode e) {
213213
result.(BreakExprCfgNode).getTarget() = e
214214
}
215215

216+
/**
217+
* Holds if a reverse local flow step should be added from the post-update node
218+
* for `e` to the post-update node for the result.
219+
*
220+
* This is needed to allow for side-effects on compound expressions to propagate
221+
* to sub components. For example, in
222+
*
223+
* ```rust
224+
* ({ foo(); &mut a}).set_data(taint);
225+
* ```
226+
*
227+
* we add a reverse flow step from `[post] { foo(); &mut a}` to `[post] &mut a`,
228+
* in order for the side-effect of `set_data` to reach `&mut a`.
229+
*/
216230
ExprCfgNode getPostUpdateReverseStep(ExprCfgNode e, boolean preservesValue) {
217231
result = getALastEvalNode(e) and
218232
preservesValue = true

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ abstract class NodePublic extends TNode {
2929
/**
3030
* Gets the expression that corresponds to this node, if any.
3131
*/
32-
ExprCfgNode asExpr() { none() }
32+
final ExprCfgNode asExpr() { this = TExprNode(result) }
3333

3434
/**
3535
* Gets the parameter that corresponds to this node, if any.
@@ -39,7 +39,7 @@ abstract class NodePublic extends TNode {
3939
/**
4040
* Gets the pattern that corresponds to this node, if any.
4141
*/
42-
PatCfgNode asPat() { none() }
42+
final PatCfgNode asPat() { this = TPatNode(result) }
4343
}
4444

4545
abstract class Node extends NodePublic {
@@ -144,16 +144,12 @@ class ExprNode extends AstCfgFlowNode, TExprNode {
144144
override ExprCfgNode n;
145145

146146
ExprNode() { this = TExprNode(n) }
147-
148-
override ExprCfgNode asExpr() { result = n }
149147
}
150148

151149
final class PatNode extends AstCfgFlowNode, TPatNode {
152150
override PatCfgNode n;
153151

154152
PatNode() { this = TPatNode(n) }
155-
156-
override PatCfgNode asPat() { result = n }
157153
}
158154

159155
/** A data flow node that corresponds to a name node in the CFG. */
@@ -467,16 +463,13 @@ newtype TNode =
467463
or
468464
e =
469465
[
470-
any(IndexExprCfgNode i).getBase(), any(FieldExprCfgNode access).getExpr(),
471-
any(TryExprCfgNode try).getExpr(),
472-
any(PrefixExprCfgNode pe | pe.getOperatorName() = "*").getExpr(),
473-
any(AwaitExprCfgNode a).getExpr(), any(MethodCallExprCfgNode mc).getReceiver()
466+
any(IndexExprCfgNode i).getBase(), //
467+
any(FieldExprCfgNode access).getExpr(), //
468+
any(TryExprCfgNode try).getExpr(), //
469+
any(PrefixExprCfgNode pe | pe.getOperatorName() = "*").getExpr(), //
470+
any(AwaitExprCfgNode a).getExpr(), any(MethodCallExprCfgNode mc).getReceiver(), //
471+
getPostUpdateReverseStep(any(PostUpdateNode n).getPreUpdateNode().asExpr(), _)
474472
]
475-
or
476-
exists(ExprCfgNode pred |
477-
exists(TExprPostUpdateNode(pred)) and
478-
e = getPostUpdateReverseStep(pred, _)
479-
)
480473
} or
481474
TReceiverNode(MethodCallExprCfgNode mc, Boolean isPost) or
482475
TSsaNode(SsaImpl::DataFlowIntegration::SsaNode node) or

0 commit comments

Comments
 (0)