Skip to content

Rust: Add reverse post-update flow steps #19106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 26, 2025

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Mar 25, 2025

Adds (restricted) reverse flow steps for post-update nodes. For example, in a call like

({ 42; &mut a}).set_data(source(9));

we add a flow step from [post] { 42; &mut a} to [post] &mut a to allow for side effects on the receiver to be reach &mut a.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Mar 25, 2025
@hvitved hvitved force-pushed the rust/reverse-post-update-steps branch from 71f86d2 to 18e55b8 Compare March 25, 2025 08:26
@hvitved hvitved marked this pull request as ready for review March 25, 2025 12:45
@hvitved hvitved requested review from Copilot and paldepind March 25, 2025 12:45
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces reverse post-update flow steps to handle side effects on receivers in post-update nodes.

  • Introduces a new struct MyStruct with set_data and get_data methods.
  • Adds two test functions (data_out_of_call_side_effect1 and data_out_of_call_side_effect2) to verify the reverse flow steps.
  • Updates main() to invoke the new test functions.
Files not reviewed (9)
  • rust/ql/lib/codeql/rust/dataflow/internal/DataFlowConsistency.qll: Language not supported
  • rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll: Language not supported
  • rust/ql/lib/codeql/rust/dataflow/internal/Node.qll: Language not supported
  • rust/ql/lib/codeql/rust/dataflow/internal/SsaImpl.qll: Language not supported
  • rust/ql/lib/codeql/rust/dataflow/internal/TaintTrackingImpl.qll: Language not supported
  • rust/ql/test/library-tests/dataflow/global/inline-flow.expected: Language not supported
  • rust/ql/test/library-tests/dataflow/global/viableCallable.expected: Language not supported
  • rust/ql/test/library-tests/dataflow/local/DataFlowStep.expected: Language not supported
  • rust/ql/test/library-tests/dataflow/taint/TaintFlowStep.expected: Language not supported

Tip: Copilot only keeps its highest confidence comments to reduce noise and keep you focused. Learn more


impl MyStruct {
fn set_data(&mut self, n: i64) {
(*self).data = n // todo: implicit deref not yet supported
Copy link
Preview

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.

The assignment statement is missing a semicolon, which could cause a compile error. Please add a semicolon at the end of the assignment.

Suggested change
(*self).data = n // todo: implicit deref not yet supported
(*self).data = n; // todo: implicit deref not yet supported

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Copy link
Contributor

@paldepind paldepind left a comment

Choose a reason for hiding this comment

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

Nice!

Copy link
Contributor

@paldepind paldepind left a comment

Choose a reason for hiding this comment

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

Oops, I hit the wrong button. Looks great, but I've also left two comments :)

@hvitved hvitved requested a review from paldepind March 26, 2025 07:58
paldepind
paldepind previously approved these changes Mar 26, 2025
*
* we add a reverse flow step from `[post] { foo(); &mut a}` to `[post] &mut a`,
* in order for the side-effect of `set_data` to reach `&mut a`.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, this comment really helps add context 🤩

@hvitved hvitved force-pushed the rust/reverse-post-update-steps branch from 28c1c9b to f45eca7 Compare March 26, 2025 08:03
@hvitved
Copy link
Contributor Author

hvitved commented Mar 26, 2025

Rebased to resolve merge conflict.

* we add a reverse flow step from `[post] { foo(); &mut a}` to `[post] &mut a`,
* in order for the side-effect of `set_data` to reach `&mut a`.
*/
ExprCfgNode getPostUpdateReverseStep(ExprCfgNode e, boolean preservesValue) {

Check warning

Code scanning / CodeQL

Missing QLDoc for parameter Warning

The QLDoc has no documentation for preservesValue, but the QLDoc mentions set_data
@hvitved hvitved merged commit 212884c into github:main Mar 26, 2025
17 checks passed
@hvitved hvitved deleted the rust/reverse-post-update-steps branch March 26, 2025 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants