Skip to content

Commit aebce74

Browse files
committed
Rust: Create data flow nodes for parameters in the CFG
Before data flow nodes where created for all parameters in the AST. But some AST parameters does not lead to any data flow (for instance parameters in function pointer types).
1 parent 6a3d417 commit aebce74

File tree

5 files changed

+13
-21
lines changed

5 files changed

+13
-21
lines changed

rust/ql/lib/codeql/rust/controlflow/CfgNodes.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ class AstCfgNode extends CfgNode {
1414
AstCfgNode() { node = this.getAstNode() }
1515
}
1616

17+
/** A CFG node that corresponds to a parameter in the AST. */
18+
class ParamCfgNode extends AstCfgNode {
19+
override Param node;
20+
21+
/** Gets the underlying parameter. */
22+
Param getParam() { result = node }
23+
}
24+
1725
/** A CFG node that corresponds to an expression in the AST. */
1826
class ExprCfgNode extends AstCfgNode {
1927
override Expr node;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,18 @@ module Node {
152152
* flow graph.
153153
*/
154154
final class ParameterNode extends Node, TParameterNode {
155-
Param parameter;
155+
ParamCfgNode parameter;
156156

157157
ParameterNode() { this = TParameterNode(parameter) }
158158

159-
override CfgScope getCfgScope() { result = parameter.getEnclosingCallable() }
159+
override CfgScope getCfgScope() { result = parameter.getParam().getEnclosingCallable() }
160160

161161
override Location getLocation() { result = parameter.getLocation() }
162162

163163
override string toString() { result = parameter.toString() }
164164

165165
/** Gets the parameter in the AST that this node corresponds to. */
166-
Param getParameter() { result = parameter }
166+
Param getParameter() { result = parameter.getParam() }
167167
}
168168

169169
final class ArgumentNode = NaNode;
@@ -232,7 +232,7 @@ final class Node = Node::Node;
232232
module SsaFlow {
233233
private module Impl = SsaImpl::DataFlowIntegration;
234234

235-
private Node::ParameterNode toParameterNode(Param p) { result = TParameterNode(p) }
235+
private Node::ParameterNode toParameterNode(Param p) { result.getParameter() = p }
236236

237237
/** Converts a control flow node into an SSA control flow node. */
238238
Impl::Node asNode(Node n) {
@@ -484,7 +484,7 @@ private module Cached {
484484
cached
485485
newtype TNode =
486486
TExprNode(ExprCfgNode n) or
487-
TParameterNode(Param p) or
487+
TParameterNode(ParamCfgNode p) or
488488
TSsaNode(SsaImpl::DataFlowIntegration::SsaNode node)
489489

490490
cached

rust/ql/test/extractor-tests/generated/Trait/CONSISTENCY/DataFlowConsistency.expected

Lines changed: 0 additions & 2 deletions
This file was deleted.

rust/ql/test/library-tests/controlflow/CONSISTENCY/DataFlowConsistency.expected

Lines changed: 0 additions & 2 deletions
This file was deleted.

rust/ql/test/query-tests/unusedentities/CONSISTENCY/DataFlowConsistency.expected

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)