From bc4b69bb93936c646a47d76e33f0415c844c8184 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Tue, 20 May 2025 10:05:30 +0100 Subject: [PATCH 1/7] Rust: Add ComparisonOperation library. --- .../rust/elements/ComparisonOperation.qll | 66 +++++++++++++++++++ rust/ql/lib/rust.qll | 1 + .../library-tests/operations/Operations.ql | 18 +++++ rust/ql/test/library-tests/operations/test.rs | 12 ++-- 4 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll diff --git a/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll b/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll new file mode 100644 index 000000000000..e37c5db5987c --- /dev/null +++ b/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll @@ -0,0 +1,66 @@ +private import codeql.rust.elements.Expr +private import codeql.rust.elements.BinaryExpr +private import codeql.rust.elements.Operation + +/** + * A comparison operation, such as `==`, `<` or `>=`. + */ +abstract private class ComparisonOperationImpl extends Operation { } + +final class ComparisonOperation = ComparisonOperationImpl; + +/** + * An equality comparison operation, `==` or `!=`. + */ +abstract private class EqualityOperationImpl extends BinaryExpr, ComparisonOperationImpl { } + +final class EqualityOperation = EqualityOperationImpl; + +/** + * The equal comparison operation, `==`. + */ +final class EqualOperation extends EqualityOperationImpl, BinaryExpr { + EqualOperation() { this.getOperatorName() = "==" } +} + +/** + * The not equal comparison operation, `!=`. + */ +final class NotEqualOperation extends EqualityOperationImpl { + NotEqualOperation() { this.getOperatorName() = "!=" } +} + +/** + * A relational comparison operation, that is, one of `<=`, `<`, `>`, or `>=`. + */ +abstract private class RelationalOperationImpl extends BinaryExpr, ComparisonOperationImpl { } + +final class RelationalOperation = RelationalOperationImpl; + +/** + * The less than comparison operation, `<`. + */ +final class LessThanOperation extends RelationalOperationImpl, BinaryExpr { + LessThanOperation() { this.getOperatorName() = "<" } +} + +/** + * The greater than comparison operation, `>?`. + */ +final class GreaterThanOperation extends RelationalOperationImpl, BinaryExpr { + GreaterThanOperation() { this.getOperatorName() = ">" } +} + +/** + * The less than or equal comparison operation, `<=`. + */ +final class LessOrEqualOperation extends RelationalOperationImpl, BinaryExpr { + LessOrEqualOperation() { this.getOperatorName() = "<=" } +} + +/** + * The less than or equal comparison operation, `>=`. + */ +final class GreaterOrEqualOperation extends RelationalOperationImpl, BinaryExpr { + GreaterOrEqualOperation() { this.getOperatorName() = ">=" } +} diff --git a/rust/ql/lib/rust.qll b/rust/ql/lib/rust.qll index 7b97f68469ca..4a533b34badc 100644 --- a/rust/ql/lib/rust.qll +++ b/rust/ql/lib/rust.qll @@ -5,6 +5,7 @@ import codeql.Locations import codeql.files.FileSystem import codeql.rust.elements.Operation import codeql.rust.elements.AssignmentOperation +import codeql.rust.elements.ComparisonOperation import codeql.rust.elements.LiteralExprExt import codeql.rust.elements.LogicalOperation import codeql.rust.elements.AsyncBlockExpr diff --git a/rust/ql/test/library-tests/operations/Operations.ql b/rust/ql/test/library-tests/operations/Operations.ql index cbb81bdcb025..39b4279ddd68 100644 --- a/rust/ql/test/library-tests/operations/Operations.ql +++ b/rust/ql/test/library-tests/operations/Operations.ql @@ -13,6 +13,24 @@ string describe(Expr op) { op instanceof LogicalOperation and result = "LogicalOperation" or op instanceof RefExpr and result = "RefExpr" + or + op instanceof ComparisonOperation and result = "ComparisonOperation" + or + op instanceof EqualityOperation and result = "EqualityOperation" + or + op instanceof EqualOperation and result = "EqualOperation" + or + op instanceof NotEqualOperation and result = "NotEqualOperation" + or + op instanceof RelationalOperation and result = "RelationalOperation" + or + op instanceof LessThanOperation and result = "LessThanOperation" + or + op instanceof GreaterThanOperation and result = "GreaterThanOperation" + or + op instanceof LessOrEqualOperation and result = "LessOrEqualOperation" + or + op instanceof GreaterOrEqualOperation and result = "GreaterOrEqualOperation" } module OperationsTest implements TestSig { diff --git a/rust/ql/test/library-tests/operations/test.rs b/rust/ql/test/library-tests/operations/test.rs index f82a9501fef4..8b7e6764b539 100644 --- a/rust/ql/test/library-tests/operations/test.rs +++ b/rust/ql/test/library-tests/operations/test.rs @@ -11,12 +11,12 @@ fn test_operations( x = y; // $ Operation Op== Operands=2 AssignmentOperation BinaryExpr // comparison operations - x == y; // $ Operation Op=== Operands=2 BinaryExpr - x != y; // $ Operation Op=!= Operands=2 BinaryExpr - x < y; // $ Operation Op=< Operands=2 BinaryExpr - x <= y; // $ Operation Op=<= Operands=2 BinaryExpr - x > y; // $ Operation Op=> Operands=2 BinaryExpr - x >= y; // $ Operation Op=>= Operands=2 BinaryExpr + x == y; // $ Operation Op=== Operands=2 BinaryExpr ComparisonOperation EqualityOperation EqualOperation + x != y; // $ Operation Op=!= Operands=2 BinaryExpr ComparisonOperation EqualityOperation NotEqualOperation + x < y; // $ Operation Op=< Operands=2 BinaryExpr ComparisonOperation RelationalOperation LessThanOperation + x <= y; // $ Operation Op=<= Operands=2 BinaryExpr ComparisonOperation RelationalOperation LessOrEqualOperation + x > y; // $ Operation Op=> Operands=2 BinaryExpr ComparisonOperation RelationalOperation GreaterThanOperation + x >= y; // $ Operation Op=>= Operands=2 BinaryExpr ComparisonOperation RelationalOperation GreaterOrEqualOperation // arithmetic operations x + y; // $ Operation Op=+ Operands=2 BinaryExpr From ca1437adf19e8ded15b8ea5e40cf5efac324ceb9 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Tue, 20 May 2025 10:14:11 +0100 Subject: [PATCH 2/7] Rust: Move the getGreaterOperand/getLesserOperand predicates into RelationalOperation. --- .../rust/elements/ComparisonOperation.qll | 36 +++++++++++++++++-- .../UncontrolledAllocationSizeExtensions.qll | 32 ++--------------- .../library-tests/operations/Operations.ql | 12 ++++++- rust/ql/test/library-tests/operations/test.rs | 8 ++--- 4 files changed, 51 insertions(+), 37 deletions(-) diff --git a/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll b/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll index e37c5db5987c..002e011c2f05 100644 --- a/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll +++ b/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll @@ -33,7 +33,23 @@ final class NotEqualOperation extends EqualityOperationImpl { /** * A relational comparison operation, that is, one of `<=`, `<`, `>`, or `>=`. */ -abstract private class RelationalOperationImpl extends BinaryExpr, ComparisonOperationImpl { } +abstract private class RelationalOperationImpl extends BinaryExpr, ComparisonOperationImpl { + /** + * Gets the operand on the "greater" (or "greater-or-equal") side + * of this relational expression, that is, the side that is larger + * if the overall expression evaluates to `true`; for example on + * `x <= 20` this is the `20`, and on `y > 0` it is `y`. + */ + abstract Expr getGreaterOperand(); + + /** + * Gets the operand on the "lesser" (or "lesser-or-equal") side + * of this relational expression, that is, the side that is smaller + * if the overall expression evaluates to `true`; for example on + * `x <= 20` this is `x`, and on `y > 0` it is the `0`. + */ + abstract Expr getLesserOperand(); +} final class RelationalOperation = RelationalOperationImpl; @@ -42,13 +58,21 @@ final class RelationalOperation = RelationalOperationImpl; */ final class LessThanOperation extends RelationalOperationImpl, BinaryExpr { LessThanOperation() { this.getOperatorName() = "<" } + + override Expr getGreaterOperand() { result = this.getRhs() } + + override Expr getLesserOperand() { result = this.getLhs() } } /** - * The greater than comparison operation, `>?`. + * The greater than comparison operation, `>`. */ final class GreaterThanOperation extends RelationalOperationImpl, BinaryExpr { GreaterThanOperation() { this.getOperatorName() = ">" } + + override Expr getGreaterOperand() { result = this.getLhs() } + + override Expr getLesserOperand() { result = this.getRhs() } } /** @@ -56,6 +80,10 @@ final class GreaterThanOperation extends RelationalOperationImpl, BinaryExpr { */ final class LessOrEqualOperation extends RelationalOperationImpl, BinaryExpr { LessOrEqualOperation() { this.getOperatorName() = "<=" } + + override Expr getGreaterOperand() { result = this.getRhs() } + + override Expr getLesserOperand() { result = this.getLhs() } } /** @@ -63,4 +91,8 @@ final class LessOrEqualOperation extends RelationalOperationImpl, BinaryExpr { */ final class GreaterOrEqualOperation extends RelationalOperationImpl, BinaryExpr { GreaterOrEqualOperation() { this.getOperatorName() = ">=" } + + override Expr getGreaterOperand() { result = this.getLhs() } + + override Expr getLesserOperand() { result = this.getRhs() } } diff --git a/rust/ql/lib/codeql/rust/security/UncontrolledAllocationSizeExtensions.qll b/rust/ql/lib/codeql/rust/security/UncontrolledAllocationSizeExtensions.qll index b8ab16090d19..1a333a9f9e7f 100644 --- a/rust/ql/lib/codeql/rust/security/UncontrolledAllocationSizeExtensions.qll +++ b/rust/ql/lib/codeql/rust/security/UncontrolledAllocationSizeExtensions.qll @@ -43,44 +43,16 @@ module UncontrolledAllocationSize { } } - /** - * Gets the operand on the "greater" (or "greater-or-equal") side - * of this relational expression, that is, the side that is larger - * if the overall expression evaluates to `true`; for example on - * `x <= 20` this is the `20`, and on `y > 0` it is `y`. - */ - private Expr getGreaterOperand(BinaryExpr op) { - op.getOperatorName() = ["<", "<="] and - result = op.getRhs() - or - op.getOperatorName() = [">", ">="] and - result = op.getLhs() - } - - /** - * Gets the operand on the "lesser" (or "lesser-or-equal") side - * of this relational expression, that is, the side that is smaller - * if the overall expression evaluates to `true`; for example on - * `x <= 20` this is `x`, and on `y > 0` it is the `0`. - */ - private Expr getLesserOperand(BinaryExpr op) { - op.getOperatorName() = ["<", "<="] and - result = op.getLhs() - or - op.getOperatorName() = [">", ">="] and - result = op.getRhs() - } - /** * Holds if comparison `g` having result `branch` indicates an upper bound for the sub-expression * `node`. For example when the comparison `x < 10` is true, we have an upper bound for `x`. */ private predicate isUpperBoundCheck(CfgNodes::AstCfgNode g, Cfg::CfgNode node, boolean branch) { exists(BinaryExpr cmp | g = cmp.getACfgNode() | - node = getLesserOperand(cmp).getACfgNode() and + node = cmp.(RelationalOperation).getLesserOperand().getACfgNode() and branch = true or - node = getGreaterOperand(cmp).getACfgNode() and + node = cmp.(RelationalOperation).getGreaterOperand().getACfgNode() and branch = false or cmp.getOperatorName() = "==" and diff --git a/rust/ql/test/library-tests/operations/Operations.ql b/rust/ql/test/library-tests/operations/Operations.ql index 39b4279ddd68..af7ecefb1c39 100644 --- a/rust/ql/test/library-tests/operations/Operations.ql +++ b/rust/ql/test/library-tests/operations/Operations.ql @@ -34,7 +34,9 @@ string describe(Expr op) { } module OperationsTest implements TestSig { - string getARelevantTag() { result = describe(_) or result = ["Op", "Operands"] } + string getARelevantTag() { + result = describe(_) or result = ["Op", "Operands", "Greater", "Lesser"] + } predicate hasActualResult(Location location, string element, string tag, string value) { exists(Expr op | @@ -51,6 +53,14 @@ module OperationsTest implements TestSig { op instanceof Operation and tag = "Operands" and value = count(op.(Operation).getAnOperand()).toString() + or + op instanceof RelationalOperation and + tag = "Greater" and + value = op.(RelationalOperation).getGreaterOperand().toString() + or + op instanceof RelationalOperation and + tag = "Lesser" and + value = op.(RelationalOperation).getLesserOperand().toString() ) ) } diff --git a/rust/ql/test/library-tests/operations/test.rs b/rust/ql/test/library-tests/operations/test.rs index 8b7e6764b539..06c9bbe6db17 100644 --- a/rust/ql/test/library-tests/operations/test.rs +++ b/rust/ql/test/library-tests/operations/test.rs @@ -13,10 +13,10 @@ fn test_operations( // comparison operations x == y; // $ Operation Op=== Operands=2 BinaryExpr ComparisonOperation EqualityOperation EqualOperation x != y; // $ Operation Op=!= Operands=2 BinaryExpr ComparisonOperation EqualityOperation NotEqualOperation - x < y; // $ Operation Op=< Operands=2 BinaryExpr ComparisonOperation RelationalOperation LessThanOperation - x <= y; // $ Operation Op=<= Operands=2 BinaryExpr ComparisonOperation RelationalOperation LessOrEqualOperation - x > y; // $ Operation Op=> Operands=2 BinaryExpr ComparisonOperation RelationalOperation GreaterThanOperation - x >= y; // $ Operation Op=>= Operands=2 BinaryExpr ComparisonOperation RelationalOperation GreaterOrEqualOperation + x < y; // $ Operation Op=< Operands=2 BinaryExpr ComparisonOperation RelationalOperation LessThanOperation Greater=y Lesser=x + x <= y; // $ Operation Op=<= Operands=2 BinaryExpr ComparisonOperation RelationalOperation LessOrEqualOperation Greater=y Lesser=x + x > y; // $ Operation Op=> Operands=2 BinaryExpr ComparisonOperation RelationalOperation GreaterThanOperation Greater=x Lesser=y + x >= y; // $ Operation Op=>= Operands=2 BinaryExpr ComparisonOperation RelationalOperation GreaterOrEqualOperation Greater=x Lesser=y // arithmetic operations x + y; // $ Operation Op=+ Operands=2 BinaryExpr From 2b65eebbc8226bd927fca1ca3fde3b800f87eedf Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Tue, 20 May 2025 10:32:50 +0100 Subject: [PATCH 3/7] Rust: QLDoc. --- rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll | 4 ++++ rust/ql/lib/codeql/rust/elements/LogicalOperation.qll | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll b/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll index 002e011c2f05..4c20b1d38de9 100644 --- a/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll +++ b/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll @@ -1,3 +1,7 @@ +/** + * Provides classes for comparison operations. + */ + private import codeql.rust.elements.Expr private import codeql.rust.elements.BinaryExpr private import codeql.rust.elements.Operation diff --git a/rust/ql/lib/codeql/rust/elements/LogicalOperation.qll b/rust/ql/lib/codeql/rust/elements/LogicalOperation.qll index eaf1ff06b7d5..d0099be0b93c 100644 --- a/rust/ql/lib/codeql/rust/elements/LogicalOperation.qll +++ b/rust/ql/lib/codeql/rust/elements/LogicalOperation.qll @@ -1,3 +1,7 @@ +/** + * Provides classes for logical operations. + */ + private import codeql.rust.elements.Expr private import codeql.rust.elements.BinaryExpr private import codeql.rust.elements.PrefixExpr From 0feade467dc40cb34828023a9eb85ac3ff97e8d7 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Tue, 20 May 2025 10:35:02 +0100 Subject: [PATCH 4/7] Update rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll b/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll index 4c20b1d38de9..bdba5ad2c29f 100644 --- a/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll +++ b/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll @@ -91,7 +91,7 @@ final class LessOrEqualOperation extends RelationalOperationImpl, BinaryExpr { } /** - * The less than or equal comparison operation, `>=`. + * The greater than or equal comparison operation, `>=`. */ final class GreaterOrEqualOperation extends RelationalOperationImpl, BinaryExpr { GreaterOrEqualOperation() { this.getOperatorName() = ">=" } From bd004abeae7b2f11b58b8da371caaa25ea771455 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Tue, 20 May 2025 10:35:41 +0100 Subject: [PATCH 5/7] Rust: Remove redundant import. --- rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll | 1 - 1 file changed, 1 deletion(-) diff --git a/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll b/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll index bdba5ad2c29f..253dd0d19acb 100644 --- a/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll +++ b/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll @@ -2,7 +2,6 @@ * Provides classes for comparison operations. */ -private import codeql.rust.elements.Expr private import codeql.rust.elements.BinaryExpr private import codeql.rust.elements.Operation From 4ebf3adfdfffdfa78a2ac3d8dd91d95bf751d98e Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 21 May 2025 11:02:48 +0100 Subject: [PATCH 6/7] Rust: Address review comments. --- .../lib/codeql/rust/elements/ComparisonOperation.qll | 12 ++++++------ .../UncontrolledAllocationSizeExtensions.qll | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll b/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll index 253dd0d19acb..cbd9ae91a27d 100644 --- a/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll +++ b/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll @@ -6,7 +6,7 @@ private import codeql.rust.elements.BinaryExpr private import codeql.rust.elements.Operation /** - * A comparison operation, such as `==`, `<` or `>=`. + * A comparison operation, such as `==`, `<`, or `>=`. */ abstract private class ComparisonOperationImpl extends Operation { } @@ -22,7 +22,7 @@ final class EqualityOperation = EqualityOperationImpl; /** * The equal comparison operation, `==`. */ -final class EqualOperation extends EqualityOperationImpl, BinaryExpr { +final class EqualOperation extends EqualityOperationImpl { EqualOperation() { this.getOperatorName() = "==" } } @@ -59,7 +59,7 @@ final class RelationalOperation = RelationalOperationImpl; /** * The less than comparison operation, `<`. */ -final class LessThanOperation extends RelationalOperationImpl, BinaryExpr { +final class LessThanOperation extends RelationalOperationImpl { LessThanOperation() { this.getOperatorName() = "<" } override Expr getGreaterOperand() { result = this.getRhs() } @@ -70,7 +70,7 @@ final class LessThanOperation extends RelationalOperationImpl, BinaryExpr { /** * The greater than comparison operation, `>`. */ -final class GreaterThanOperation extends RelationalOperationImpl, BinaryExpr { +final class GreaterThanOperation extends RelationalOperationImpl { GreaterThanOperation() { this.getOperatorName() = ">" } override Expr getGreaterOperand() { result = this.getLhs() } @@ -81,7 +81,7 @@ final class GreaterThanOperation extends RelationalOperationImpl, BinaryExpr { /** * The less than or equal comparison operation, `<=`. */ -final class LessOrEqualOperation extends RelationalOperationImpl, BinaryExpr { +final class LessOrEqualOperation extends RelationalOperationImpl { LessOrEqualOperation() { this.getOperatorName() = "<=" } override Expr getGreaterOperand() { result = this.getRhs() } @@ -92,7 +92,7 @@ final class LessOrEqualOperation extends RelationalOperationImpl, BinaryExpr { /** * The greater than or equal comparison operation, `>=`. */ -final class GreaterOrEqualOperation extends RelationalOperationImpl, BinaryExpr { +final class GreaterOrEqualOperation extends RelationalOperationImpl { GreaterOrEqualOperation() { this.getOperatorName() = ">=" } override Expr getGreaterOperand() { result = this.getLhs() } diff --git a/rust/ql/lib/codeql/rust/security/UncontrolledAllocationSizeExtensions.qll b/rust/ql/lib/codeql/rust/security/UncontrolledAllocationSizeExtensions.qll index 1a333a9f9e7f..ab543d5a63d8 100644 --- a/rust/ql/lib/codeql/rust/security/UncontrolledAllocationSizeExtensions.qll +++ b/rust/ql/lib/codeql/rust/security/UncontrolledAllocationSizeExtensions.qll @@ -55,11 +55,11 @@ module UncontrolledAllocationSize { node = cmp.(RelationalOperation).getGreaterOperand().getACfgNode() and branch = false or - cmp.getOperatorName() = "==" and + cmp instanceof EqualOperation and [cmp.getLhs(), cmp.getRhs()].getACfgNode() = node and branch = true or - cmp.getOperatorName() = "!=" and + cmp instanceof NotEqualOperation and [cmp.getLhs(), cmp.getRhs()].getACfgNode() = node and branch = false ) From 852203911afc2f8b271660fd9264763a6ab64db8 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Thu, 22 May 2025 11:13:56 +0100 Subject: [PATCH 7/7] Rust: Equal -> Equals. --- .../codeql/rust/elements/ComparisonOperation.qll | 16 ++++++++-------- .../UncontrolledAllocationSizeExtensions.qll | 4 ++-- .../test/library-tests/operations/Operations.ql | 8 ++++---- rust/ql/test/library-tests/operations/test.rs | 8 ++++---- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll b/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll index cbd9ae91a27d..24fe9b0b19d6 100644 --- a/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll +++ b/rust/ql/lib/codeql/rust/elements/ComparisonOperation.qll @@ -22,15 +22,15 @@ final class EqualityOperation = EqualityOperationImpl; /** * The equal comparison operation, `==`. */ -final class EqualOperation extends EqualityOperationImpl { - EqualOperation() { this.getOperatorName() = "==" } +final class EqualsOperation extends EqualityOperationImpl { + EqualsOperation() { this.getOperatorName() = "==" } } /** * The not equal comparison operation, `!=`. */ -final class NotEqualOperation extends EqualityOperationImpl { - NotEqualOperation() { this.getOperatorName() = "!=" } +final class NotEqualsOperation extends EqualityOperationImpl { + NotEqualsOperation() { this.getOperatorName() = "!=" } } /** @@ -81,8 +81,8 @@ final class GreaterThanOperation extends RelationalOperationImpl { /** * The less than or equal comparison operation, `<=`. */ -final class LessOrEqualOperation extends RelationalOperationImpl { - LessOrEqualOperation() { this.getOperatorName() = "<=" } +final class LessOrEqualsOperation extends RelationalOperationImpl { + LessOrEqualsOperation() { this.getOperatorName() = "<=" } override Expr getGreaterOperand() { result = this.getRhs() } @@ -92,8 +92,8 @@ final class LessOrEqualOperation extends RelationalOperationImpl { /** * The greater than or equal comparison operation, `>=`. */ -final class GreaterOrEqualOperation extends RelationalOperationImpl { - GreaterOrEqualOperation() { this.getOperatorName() = ">=" } +final class GreaterOrEqualsOperation extends RelationalOperationImpl { + GreaterOrEqualsOperation() { this.getOperatorName() = ">=" } override Expr getGreaterOperand() { result = this.getLhs() } diff --git a/rust/ql/lib/codeql/rust/security/UncontrolledAllocationSizeExtensions.qll b/rust/ql/lib/codeql/rust/security/UncontrolledAllocationSizeExtensions.qll index ab543d5a63d8..2f4898f6e9da 100644 --- a/rust/ql/lib/codeql/rust/security/UncontrolledAllocationSizeExtensions.qll +++ b/rust/ql/lib/codeql/rust/security/UncontrolledAllocationSizeExtensions.qll @@ -55,11 +55,11 @@ module UncontrolledAllocationSize { node = cmp.(RelationalOperation).getGreaterOperand().getACfgNode() and branch = false or - cmp instanceof EqualOperation and + cmp instanceof EqualsOperation and [cmp.getLhs(), cmp.getRhs()].getACfgNode() = node and branch = true or - cmp instanceof NotEqualOperation and + cmp instanceof NotEqualsOperation and [cmp.getLhs(), cmp.getRhs()].getACfgNode() = node and branch = false ) diff --git a/rust/ql/test/library-tests/operations/Operations.ql b/rust/ql/test/library-tests/operations/Operations.ql index af7ecefb1c39..482373c8d052 100644 --- a/rust/ql/test/library-tests/operations/Operations.ql +++ b/rust/ql/test/library-tests/operations/Operations.ql @@ -18,9 +18,9 @@ string describe(Expr op) { or op instanceof EqualityOperation and result = "EqualityOperation" or - op instanceof EqualOperation and result = "EqualOperation" + op instanceof EqualsOperation and result = "EqualsOperation" or - op instanceof NotEqualOperation and result = "NotEqualOperation" + op instanceof NotEqualsOperation and result = "NotEqualsOperation" or op instanceof RelationalOperation and result = "RelationalOperation" or @@ -28,9 +28,9 @@ string describe(Expr op) { or op instanceof GreaterThanOperation and result = "GreaterThanOperation" or - op instanceof LessOrEqualOperation and result = "LessOrEqualOperation" + op instanceof LessOrEqualsOperation and result = "LessOrEqualsOperation" or - op instanceof GreaterOrEqualOperation and result = "GreaterOrEqualOperation" + op instanceof GreaterOrEqualsOperation and result = "GreaterOrEqualsOperation" } module OperationsTest implements TestSig { diff --git a/rust/ql/test/library-tests/operations/test.rs b/rust/ql/test/library-tests/operations/test.rs index 06c9bbe6db17..dba47f5faa3d 100644 --- a/rust/ql/test/library-tests/operations/test.rs +++ b/rust/ql/test/library-tests/operations/test.rs @@ -11,12 +11,12 @@ fn test_operations( x = y; // $ Operation Op== Operands=2 AssignmentOperation BinaryExpr // comparison operations - x == y; // $ Operation Op=== Operands=2 BinaryExpr ComparisonOperation EqualityOperation EqualOperation - x != y; // $ Operation Op=!= Operands=2 BinaryExpr ComparisonOperation EqualityOperation NotEqualOperation + x == y; // $ Operation Op=== Operands=2 BinaryExpr ComparisonOperation EqualityOperation EqualsOperation + x != y; // $ Operation Op=!= Operands=2 BinaryExpr ComparisonOperation EqualityOperation NotEqualsOperation x < y; // $ Operation Op=< Operands=2 BinaryExpr ComparisonOperation RelationalOperation LessThanOperation Greater=y Lesser=x - x <= y; // $ Operation Op=<= Operands=2 BinaryExpr ComparisonOperation RelationalOperation LessOrEqualOperation Greater=y Lesser=x + x <= y; // $ Operation Op=<= Operands=2 BinaryExpr ComparisonOperation RelationalOperation LessOrEqualsOperation Greater=y Lesser=x x > y; // $ Operation Op=> Operands=2 BinaryExpr ComparisonOperation RelationalOperation GreaterThanOperation Greater=x Lesser=y - x >= y; // $ Operation Op=>= Operands=2 BinaryExpr ComparisonOperation RelationalOperation GreaterOrEqualOperation Greater=x Lesser=y + x >= y; // $ Operation Op=>= Operands=2 BinaryExpr ComparisonOperation RelationalOperation GreaterOrEqualsOperation Greater=x Lesser=y // arithmetic operations x + y; // $ Operation Op=+ Operands=2 BinaryExpr