Skip to content

Commit a4ddab9

Browse files
committed
wip
1 parent ec39c93 commit a4ddab9

File tree

98 files changed

+2011
-1640
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+2011
-1640
lines changed

rust/ql/examples/snippets/simple_constant_password.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module ConstantPasswordConfig implements DataFlow::ConfigSig {
3434
call.getStaticTarget() = target and
3535
v.getParameter() = target.getParam(argIndex) and
3636
v.getText().matches("pass%") and
37-
call.getArg(argIndex) = node.asExpr()
37+
call.getArgument(argIndex) = node.asExpr()
3838
)
3939
}
4040
}

rust/ql/examples/snippets/simple_sql_injection.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module SqlInjectionConfig implements DataFlow::ConfigSig {
2525
// `node` is the first argument of a call to `sqlx_core::query::query`
2626
exists(CallExpr call |
2727
call.getStaticTarget().getCanonicalPath() = "sqlx_core::query::query" and
28-
call.getArg(0) = node.asExpr()
28+
call.getArgument(0) = node.asExpr()
2929
)
3030
}
3131
}

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

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
private import rust
7-
private import codeql.rust.elements.Call
87
private import ControlFlowGraph
98
private import internal.ControlFlowGraphImpl as CfgImpl
109
private import internal.CfgNodes
@@ -201,62 +200,67 @@ final class BreakExprCfgNode extends Nodes::BreakExprCfgNode {
201200
}
202201

203202
/**
204-
* A function or method call expression. See `CallExpr` and `MethodCallExpr` for further details.
203+
* A method call expression. For example:
204+
* ```rust
205+
* x.foo(42);
206+
* x.foo::<u32, u64>(42);
207+
* ```
205208
*/
206-
final class CallExprBaseCfgNode extends Nodes::CallExprBaseCfgNode {
207-
private CallExprBaseChildMapping node;
209+
final class MethodCallExprCfgNode extends Nodes::MethodCallExprCfgNode {
210+
private MethodCallExprChildMapping node;
208211

209-
CallExprBaseCfgNode() { node = this.getAstNode() }
212+
MethodCallExprCfgNode() { node = this.getAstNode() }
210213

211214
/** Gets the `i`th argument of this call. */
212215
ExprCfgNode getArgument(int i) {
213216
any(ChildMapping mapping).hasCfgChild(node, node.getArgList().getArg(i), this, result)
214217
}
215218
}
216219

217-
/**
218-
* A method call expression. For example:
219-
* ```rust
220-
* x.foo(42);
221-
* x.foo::<u32, u64>(42);
222-
* ```
223-
*/
224-
final class MethodCallExprCfgNode extends CallExprBaseCfgNode, Nodes::MethodCallExprCfgNode { }
225-
226220
/**
227221
* A CFG node that calls a function.
228222
*
229223
* This class abstract over the different ways in which a function can be called in Rust.
230224
*/
231-
final class CallCfgNode extends ExprCfgNode {
232-
private Call node;
225+
final class CallExprCfgNode extends ExprCfgNode {
226+
private CallExpr node;
233227

234-
CallCfgNode() { node = this.getAstNode() }
228+
CallExprCfgNode() { node = this.getAstNode() }
235229

236230
/** Gets the underlying `Call`. */
237-
Call getCall() { result = node }
231+
CallExpr getCall() { result = node }
238232

239233
/** Gets the receiver of this call if it is a method call. */
240234
ExprCfgNode getReceiver() {
241235
any(ChildMapping mapping).hasCfgChild(node, node.getReceiver(), this, result)
242236
}
243237

244238
/** Gets the `i`th argument of this call, if any. */
245-
ExprCfgNode getPositionalArgument(int i) {
246-
any(ChildMapping mapping).hasCfgChild(node, node.getPositionalArgument(i), this, result)
239+
ExprCfgNode getArgument(int i) {
240+
any(ChildMapping mapping).hasCfgChild(node, node.getArgument(i), this, result)
247241
}
248242
}
249243

250244
/**
251-
* A function call expression. For example:
245+
* An expression with parenthesized arguments. For example:
252246
* ```rust
253247
* foo(42);
254248
* foo::<u32, u64>(42);
255249
* foo[0](42);
256250
* foo(1) = 4;
251+
* Option::Some(42);
257252
* ```
258253
*/
259-
final class CallExprCfgNode extends CallExprBaseCfgNode, Nodes::CallExprCfgNode { }
254+
final class ParenArgsExprCfgNode extends Nodes::ParenArgsExprCfgNode {
255+
private ParenArgsExprChildMapping node;
256+
257+
ParenArgsExprCfgNode() { node = this.getAstNode() }
258+
259+
/** Gets the `i`th argument of this call. */
260+
ExprCfgNode getArgument(int i) {
261+
any(ChildMapping mapping).hasCfgChild(node, node.getArgList().getArg(i), this, result)
262+
}
263+
}
260264

261265
/**
262266
* A FormatArgsExpr. For example:

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ class BreakExprTargetChildMapping extends ParentAstNode, Expr {
5757
override predicate relevantChild(AstNode child) { child.(BreakExpr).getTarget() = this }
5858
}
5959

60-
class CallExprBaseChildMapping extends ParentAstNode, CallExprBase {
61-
override predicate relevantChild(AstNode child) { child = this.getAnArg() }
60+
class ParenArgsExprChildMapping extends ParentAstNode, ParenArgsExpr {
61+
override predicate relevantChild(AstNode child) { child = this.getArgList().getAnArg() }
62+
}
63+
64+
class MethodCallExprChildMapping extends ParentAstNode, MethodCallExpr {
65+
override predicate relevantChild(AstNode child) { child = this.getArgList().getAnArg() }
6266
}
6367

6468
class StructExprChildMapping extends ParentAstNode, StructExpr {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ module ExprTrees {
292292
}
293293
}
294294

295-
class CallExprTree extends StandardPostOrderTree instanceof CallExpr {
295+
class CallExprTree extends StandardPostOrderTree instanceof ParenArgsExpr {
296296
override AstNode getChildNode(int i) {
297-
i = 0 and result = super.getFunction()
297+
i = 0 and result = super.getBase()
298298
or
299299
result = super.getArgList().getArg(i - 1)
300300
}
@@ -512,7 +512,7 @@ module ExprTrees {
512512

513513
class MethodCallExprTree extends StandardPostOrderTree, MethodCallExpr {
514514
override AstNode getChildNode(int i) {
515-
if i = 0 then result = this.getReceiver() else result = this.getArg(i - 1)
515+
if i = 0 then result = this.getReceiver() else result = this.getArgList().getArg(i - 1)
516516
}
517517
}
518518

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,6 @@ newtype TContent =
269269
)]
270270
} or
271271
TFunctionCallReturnContent() or
272-
TFunctionCallArgumentContent(int pos) {
273-
pos in [0 .. any(CallExpr c).getArgList().getNumberOfArgs() - 1]
274-
} or
272+
TFunctionCallArgumentContent(int pos) { pos in [0 .. any(CallExpr c).getNumberOfArgs() - 1] } or
275273
TCapturedVariableContent(VariableCapture::CapturedVariable v) or
276274
TReferenceContent()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private module Input implements InputSig<Location, RustDataFlow> {
2121
or
2222
// We allow flow into post-update node for receiver expressions (from the
2323
// synthetic post receiever node).
24-
n.(Node::PostUpdateNode).getPreUpdateNode().asExpr() = any(Node::ReceiverNode r).getReceiver()
24+
n.(Node::PostUpdateNode).getPreUpdateNode().asExpr() = any(Node::DerefBorrowNode r).getNode()
2525
or
2626
n.(Node::PostUpdateNode).getPreUpdateNode().asExpr() = getPostUpdateReverseStep(_, _)
2727
or

0 commit comments

Comments
 (0)