Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions rust/ql/lib/codeql/rust/dataflow/internal/FlowSummaryImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,30 @@ private module StepsInput implements Impl::Private::StepsInputSig {
result.asCallBaseExprCfgNode().getCallExprBase() = sc.(LibraryCallable).getACall()
}

private Expr getArg(CallExprBase call, ParameterPosition pos) {
result = call.getArgList().getArg(pos.getPosition())
or
result = call.(MethodCallExpr).getReceiver() and pos.isSelf()
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make this a member predicate on ParameterPosition?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


RustDataFlow::Node getSourceNode(Input::SourceBase source, Impl::Private::SummaryComponent sc) {
sc = Impl::Private::SummaryComponent::return(_) and
result.asExpr().getExpr() = source.getCall()
or
exists(CallExprBase call, Expr arg, ParameterPosition pos |
result.(RustDataFlow::PostUpdateNode).getPreUpdateNode().asExpr().getExpr() = arg and
sc = Impl::Private::SummaryComponent::argument(pos) and
call = source.getCall() and
arg = getArg(call, pos)
)
}

RustDataFlow::Node getSinkNode(Input::SinkBase sink, Impl::Private::SummaryComponent sc) {
exists(CallExprBase call, Expr arg, ParameterPosition pos |
result.asExpr().getExpr() = arg and
sc = Impl::Private::SummaryComponent::argument(pos) and
call = sink.getCall()
|
arg = call.getArgList().getArg(pos.getPosition())
or
arg = call.(MethodCallExpr).getReceiver() and pos.isSelf()
call = sink.getCall() and
arg = getArg(call, pos)
)
}
}
Expand Down
10 changes: 10 additions & 0 deletions rust/ql/test/library-tests/dataflow/models/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ fn test_simple_sink() {
simple_sink(s); // $ hasValueFlow=17
}

// has a source model
fn arg_source(i: i64) {}

fn test_arg_source() {
let i = 19;
arg_source(i);
sink(i) // $ hasValueFlow=i
Copy link

Copilot AI Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a semicolon after the sink(i) call for consistency with other test cases and to prevent potential compilation issues.

Suggested change
sink(i) // $ hasValueFlow=i
sink(i); // $ hasValueFlow=i

Copilot uses AI. Check for mistakes.
}

#[tokio::main]
async fn main() {
test_identify();
Expand All @@ -299,5 +308,6 @@ async fn main() {
test_simple_source();
test_simple_sink();
test_get_async_number().await;
test_arg_source();
let dummy = Some(0); // ensure that the the `lang:core` crate is extracted
}
Loading