Skip to content

Commit f213a2d

Browse files
committed
Rust: CFG for ImplicitVariableAccess
1 parent 8a5fa9b commit f213a2d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,31 @@ class ParamTree extends StandardPostOrderTree, Param {
8989
override AstNode getChildNode(int i) { i = 0 and result = this.getPat() }
9090
}
9191

92+
class FormatArgsExprTree extends StandardPostOrderTree, FormatArgsExpr {
93+
override AstNode getChildNode(int i) {
94+
i = -1 and result = this.getTemplate()
95+
or
96+
result = this.getArg(i).getExpr()
97+
or
98+
result =
99+
any(ImplicitVariableAccess v, Format f, int index, int kind |
100+
f = this.getFormat(index) and
101+
(
102+
v.getArgument() = f.getArgumentRef() and kind = 0
103+
or
104+
v.getArgument() = f.getWidthArgument() and kind = 1
105+
or
106+
v.getArgument() = f.getPrecisionArgument() and kind = 2
107+
) and
108+
i = this.getNumberOfArgs() + index * 3 + kind
109+
|
110+
v
111+
)
112+
}
113+
}
114+
115+
class ImplictVariableAccessTree extends LeafTree, ImplicitVariableAccess { }
116+
92117
class ItemTree extends LeafTree, Item {
93118
ItemTree() {
94119
not this instanceof MacroCall and

rust/ql/lib/rust.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ import codeql.files.FileSystem
66
import codeql.rust.elements.AssignmentOperation
77
import codeql.rust.elements.LogicalOperation
88
import codeql.rust.elements.Variable
9+
import codeql.rust.elements.FormatTemplate

0 commit comments

Comments
 (0)