Skip to content

Rust: Add ComparisonOperation library.#19535

Merged
geoffw0 merged 8 commits intogithub:mainfrom
geoffw0:operations2
May 22, 2025
Merged

Rust: Add ComparisonOperation library.#19535
geoffw0 merged 8 commits intogithub:mainfrom
geoffw0:operations2

Conversation

@geoffw0
Copy link
Copy Markdown
Contributor

@geoffw0 geoffw0 commented May 20, 2025

Adds a ComparisonOperation library, filling out more of the Operation class tree.

Cleans up some out of place predicates (getGreaterOperand and getLesserOperand) in UncontrolledAllocationSizeExtensions.qll.

Copilot AI review requested due to automatic review settings May 20, 2025 09:29
@geoffw0 geoffw0 requested a review from a team as a code owner May 20, 2025 09:29
@geoffw0 geoffw0 added no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code labels May 20, 2025
Copy link
Copy Markdown
Contributor

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

Adds a new ComparisonOperation library to model comparison, equality, and relational operations in Rust QL, updates imports and cleans up legacy operand predicates, and extends library-tests to verify the new classes and operand tags.

  • Introduced ComparisonOperation.qll defining comparison, equality, and relational operations with getGreaterOperand/getLesserOperand.
  • Updated rust.qll import and refactored UncontrolledAllocationSizeExtensions.qll to use the new API.
  • Extended test.rs and Operations.ql to include new tags (ComparisonOperation, EqualityOperation, specific operation classes, and Greater/Lesser).

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll New file defining ComparisonOperation, its subtypes, and operand accessors.
rust/ql/lib/rust.qll Imported ComparisonOperation into the Rust library root.
rust/ql/lib/codeql/rust/security/UncontrolledAllocationSizeExtensions.qll Removed old operand helpers and switched to the new RelationalOperation API.
rust/ql/test/library-tests/operations/Operations.ql Updated describe and test harness to recognize new operation tags.
rust/ql/test/library-tests/operations/test.rs Added expected tags for comparison operations and Greater/Lesser values.

Comment thread rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll Outdated
Comment thread rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll Fixed
Comment thread rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll Outdated
/**
* The equal comparison operation, `==`.
*/
final class EqualOperation extends EqualityOperationImpl, BinaryExpr {
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.

BinaryExpr can be removed

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.

I think I prefer EqualityOperation.

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.

EqualityOperation is "an operation to do with equality", i.e. == or !=.

EqualOperation is specifically ==.

We can't use "EqualityOperation" to describe both.

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.

Removed redundant BinaryExpr.

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.

OK. Then I think I slightly prefer Equal_s_Operation over EqualOperation, but I'll let you decide.

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.

Yeah, I agree that's a better name. Updated.

Comment thread rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll Outdated
Comment thread rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll Outdated
Comment thread rust/ql/lib/codeql/rust/security/UncontrolledAllocationSizeExtensions.qll Outdated
@geoffw0
Copy link
Copy Markdown
Contributor Author

geoffw0 commented May 21, 2025

Thanks for the review suggestions. I've implemented all but one (see above).

hvitved
hvitved previously approved these changes May 22, 2025
@geoffw0 geoffw0 merged commit d27596a into github:main May 22, 2025
17 checks passed
@geoffw0 geoffw0 deleted the operations2 branch April 15, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants