Skip to content
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

Rust: Never skip assignment LHS in data flow #18292

Merged
merged 2 commits into from
Dec 17, 2024

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Dec 16, 2024

Always including the left-hand side of an assignment in data flow path graphs make it easier to follow flow. The same goes for scrutinee and patterns in match expressions.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Dec 16, 2024
@hvitved hvitved force-pushed the rust/never-skip-lhs branch from b59103e to ddd05b5 Compare December 16, 2024 14:12
@hvitved hvitved marked this pull request as ready for review December 16, 2024 18:23
@Copilot Copilot bot review requested due to automatic review settings December 16, 2024 18:23

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.

Files not reviewed (7)
  • rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll: Language not supported
  • rust/ql/test/library-tests/dataflow/barrier/inline-flow.expected: Language not supported
  • rust/ql/test/library-tests/dataflow/closures/inline-flow.expected: Language not supported
  • rust/ql/test/library-tests/dataflow/global/inline-flow.expected: Language not supported
  • rust/ql/test/library-tests/dataflow/local/inline-flow.expected: Language not supported
  • rust/ql/test/library-tests/dataflow/models/models.expected: Language not supported
  • rust/ql/test/library-tests/dataflow/taint/inline-taint-flow.expected: Language not supported

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

@hvitved hvitved requested a review from paldepind December 17, 2024 08:33
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.

This seems really nice!

Where these nodes hidden due to some defaults in the data flow library? They where not covered by our nodeIsHidden as far as I can tell.

Comment on lines +859 to +861
node.getCfgNode() = any(LetStmtCfgNode s).getPat()
or
node.getCfgNode() = any(AssignmentExprCfgNode a).getLhs()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
node.getCfgNode() = any(LetStmtCfgNode s).getPat()
or
node.getCfgNode() = any(AssignmentExprCfgNode a).getLhs()
node.getCfgNode() = [any(LetStmtCfgNode s).getPat(), any(AssignmentExprCfgNode a).getLhs()]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Making this change results in

Could not determine type of set literal. For set literals, the type must be one of the types of the elements, but neither CfgNodes::MakeCfgNodes<Locations::Location, CfgNodes::CfgNodesInput>::Nodes::PatCfgNode nor CfgNodes::MakeCfgNodes<Locations::Location, CfgNodes::CfgNodesInput>::Nodes::ExprCfgNode is a supertype of the other.

Which means one has to instead write

node.getCfgNode() =
      [any(LetStmtCfgNode s).getPat().(CfgNode), any(AssignmentExprCfgNode a).getLhs().(CfgNode)]

and then I prefer the above.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see :)

Comment on lines +864 to +865
node.asExpr() = match.getScrutinee() or
node.asExpr() = match.getArmPat(_)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
node.asExpr() = match.getScrutinee() or
node.asExpr() = match.getArmPat(_)
node.asExpr() = [match.getScrutinee(), match.getArmPat(_)]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same.

@hvitved
Copy link
Contributor Author

hvitved commented Dec 17, 2024

Where these nodes hidden due to some defaults in the data flow library? They where not covered by our nodeIsHidden as far as I can tell.

Nodes may be hidden because the data flow library compresses long local flow paths using a big-step relation. The predicate neverSkipInPathGraph tells the data flow library to never skip over certain nodes.

@hvitved hvitved merged commit 8efd870 into github:main Dec 17, 2024
14 checks passed
@hvitved hvitved deleted the rust/never-skip-lhs branch December 17, 2024 12:18
@paldepind
Copy link
Contributor

Nodes may be hidden because the data flow library compresses long local flow paths using a big-step relation. The predicate neverSkipInPathGraph tells the data flow library to never skip over certain nodes.

I see. Thanks 🙏

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