Skip to content

Commit d6d3028

Browse files
committed
Rust: Support Argument[x] MaD source definitions
1 parent cf1b19f commit d6d3028

File tree

3 files changed

+82
-59
lines changed

3 files changed

+82
-59
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,30 @@ private module StepsInput implements Impl::Private::StepsInputSig {
143143
result.asCallBaseExprCfgNode().getCallExprBase() = sc.(LibraryCallable).getACall()
144144
}
145145

146+
private Expr getArg(CallExprBase call, ParameterPosition pos) {
147+
result = call.getArgList().getArg(pos.getPosition())
148+
or
149+
result = call.(MethodCallExpr).getReceiver() and pos.isSelf()
150+
}
151+
146152
RustDataFlow::Node getSourceNode(Input::SourceBase source, Impl::Private::SummaryComponent sc) {
147153
sc = Impl::Private::SummaryComponent::return(_) and
148154
result.asExpr().getExpr() = source.getCall()
155+
or
156+
exists(CallExprBase call, Expr arg, ParameterPosition pos |
157+
result.(RustDataFlow::PostUpdateNode).getPreUpdateNode().asExpr().getExpr() = arg and
158+
sc = Impl::Private::SummaryComponent::argument(pos) and
159+
call = source.getCall() and
160+
arg = getArg(call, pos)
161+
)
149162
}
150163

151164
RustDataFlow::Node getSinkNode(Input::SinkBase sink, Impl::Private::SummaryComponent sc) {
152165
exists(CallExprBase call, Expr arg, ParameterPosition pos |
153166
result.asExpr().getExpr() = arg and
154167
sc = Impl::Private::SummaryComponent::argument(pos) and
155-
call = sink.getCall()
156-
|
157-
arg = call.getArgList().getArg(pos.getPosition())
158-
or
159-
arg = call.(MethodCallExpr).getReceiver() and pos.isSelf()
168+
call = sink.getCall() and
169+
arg = getArg(call, pos)
160170
)
161171
}
162172
}

rust/ql/test/library-tests/dataflow/models/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ fn arg_source(i: i64) {}
285285
fn test_arg_source() {
286286
let i = 19;
287287
arg_source(i);
288-
sink(i) // $ MISSING: hasValueFlow=i
288+
sink(i) // $ hasValueFlow=i
289289
}
290290

291291
#[tokio::main]

0 commit comments

Comments
 (0)