diff --git a/csharp/ql/lib/semmle/code/csharp/dataflow/Bound.qll b/csharp/ql/lib/semmle/code/csharp/dataflow/Bound.qll index b37222c1daa..c08e2e1c0d4 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/Bound.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/Bound.qll @@ -11,24 +11,4 @@ private import codeql.rangeanalysis.Bound as SharedBound private module BoundImpl = SharedBound::Bound; -/** - * A bound that may be inferred for an expression plus/minus an integer delta. - */ -class Bound = BoundImpl::Bound; - -/** - * The bound that corresponds to the integer 0. This is used to represent all - * integer bounds as bounds are always accompanied by an added integer delta. - */ -class ZeroBound = BoundImpl::ZeroBound; - -/** - * A bound corresponding to the value of an SSA variable. - */ -class SsaBound = BoundImpl::SsaBound; - -/** - * A bound that corresponds to the value of a specific expression that might be - * interesting, but isn't otherwise represented by the value of an SSA variable. - */ -class ExprBound = BoundImpl::ExprBound; \ No newline at end of file +import BoundImpl diff --git a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/BoundSpecific.qll b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/BoundSpecific.qll index 069f0034eed..9d36d6a81b5 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/BoundSpecific.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/BoundSpecific.qll @@ -10,23 +10,19 @@ private import semmle.code.csharp.dataflow.internal.rangeanalysis.SsaUtils as SU private import codeql.rangeanalysis.Bound as SharedBound /** Holds if `e` is a bound expression and it is not an SSA variable read. */ - - module BoundDefs implements SharedBound::BoundDefinitions { - class Type = CS::Type; + class Type = CS::Type; - class SsaVariable = SU::SsaVariable; - - class SsaSourceVariable = Ssa::SourceVariable; + class SsaVariable = SU::SsaVariable; - class Expr = CS::ControlFlowNodes::ExprNode; + class SsaSourceVariable = Ssa::SourceVariable; - class IntegralType = CS::IntegralType; + class Expr = CS::ControlFlowNodes::ExprNode; - class ConstantIntegerExpr = CU::ConstantIntegerExpr; + class IntegralType = CS::IntegralType; + + class ConstantIntegerExpr = CU::ConstantIntegerExpr; /** Holds if `e` is a bound expression and it is not an SSA variable read. */ - predicate interestingExprBound(Expr e) { - CU::systemArrayLengthAccess(e.getExpr()) - } + predicate interestingExprBound(Expr e) { CU::systemArrayLengthAccess(e.getExpr()) } } diff --git a/java/ql/lib/semmle/code/java/dataflow/Bound.qll b/java/ql/lib/semmle/code/java/dataflow/Bound.qll index 0cfe3e9039d..f82afcd17e4 100644 --- a/java/ql/lib/semmle/code/java/dataflow/Bound.qll +++ b/java/ql/lib/semmle/code/java/dataflow/Bound.qll @@ -10,24 +10,4 @@ private import codeql.rangeanalysis.Bound as SharedBound private module BoundImpl = SharedBound::Bound; -/** - * A bound that may be inferred for an expression plus/minus an integer delta. - */ -class Bound = BoundImpl::Bound; - -/** - * The bound that corresponds to the integer 0. This is used to represent all - * integer bounds as bounds are always accompanied by an added integer delta. - */ -class ZeroBound = BoundImpl::ZeroBound; - -/** - * A bound corresponding to the value of an SSA variable. - */ -class SsaBound = BoundImpl::SsaBound; - -/** - * A bound that corresponds to the value of a specific expression that might be - * interesting, but isn't otherwise represented by the value of an SSA variable. - */ -class ExprBound = BoundImpl::ExprBound; \ No newline at end of file +import BoundImpl diff --git a/java/ql/lib/semmle/code/java/dataflow/internal/rangeanalysis/BoundSpecific.qll b/java/ql/lib/semmle/code/java/dataflow/internal/rangeanalysis/BoundSpecific.qll index ba2f8027b30..5435eeb4492 100644 --- a/java/ql/lib/semmle/code/java/dataflow/internal/rangeanalysis/BoundSpecific.qll +++ b/java/ql/lib/semmle/code/java/dataflow/internal/rangeanalysis/BoundSpecific.qll @@ -29,4 +29,4 @@ module BoundDefs implements SharedBound::BoundDefinitions { predicate interestingExprBound(Expr e) { e.(J::FieldRead).getField() instanceof J::ArrayLengthField } -} \ No newline at end of file +} diff --git a/shared/rangeanalysis/codeql/rangeanalysis/Bound.qll b/shared/rangeanalysis/codeql/rangeanalysis/Bound.qll index 10ef74d4001..af44e692745 100644 --- a/shared/rangeanalysis/codeql/rangeanalysis/Bound.qll +++ b/shared/rangeanalysis/codeql/rangeanalysis/Bound.qll @@ -5,48 +5,53 @@ private import codeql.util.Location signature module BoundDefinitions { - class Type; - class IntegralType extends Type; + class Type; - class ConstantIntegerExpr extends Expr { - int getIntValue(); - } + class IntegralType extends Type; - class SsaSourceVariable { - Type getType(); - } + class ConstantIntegerExpr extends Expr { + int getIntValue(); + } - class SsaVariable { - SsaSourceVariable getSourceVariable(); - string toString(); - Location getLocation(); - Expr getAUse(); - } + class SsaSourceVariable { + Type getType(); + } - class Expr { - string toString(); - Location getLocation(); - } + class SsaVariable { + SsaSourceVariable getSourceVariable(); - predicate interestingExprBound(Expr e); + string toString(); + + Location getLocation(); + + Expr getAUse(); + } + + class Expr { + string toString(); + + Location getLocation(); + } + + predicate interestingExprBound(Expr e); } overlay[local?] module Bound Defs> { - private import Defs + private import Defs - private newtype TBound = + private newtype TBound = TBoundZero() or TBoundSsa(SsaVariable v) { v.getSourceVariable().getType() instanceof IntegralType } or TBoundExpr(Expr e) { - interestingExprBound(e) and - not exists(SsaVariable v | e = v.getAUse()) + interestingExprBound(e) and + not exists(SsaVariable v | e = v.getAUse()) } - /** - * A bound that may be inferred for an expression plus/minus an integer delta. - */ - abstract class Bound extends TBound { + /** + * A bound that may be inferred for an expression plus/minus an integer delta. + */ + abstract class Bound extends TBound { /** Gets a textual representation of this bound. */ abstract string toString(); @@ -58,24 +63,24 @@ module Bound Defs> { /** Gets the location of this bound. */ abstract Location getLocation(); - } + } - /** - * The bound that corresponds to the integer 0. This is used to represent all - * integer bounds as bounds are always accompanied by an added integer delta. - */ - class ZeroBound extends Bound, TBoundZero { + /** + * The bound that corresponds to the integer 0. This is used to represent all + * integer bounds as bounds are always accompanied by an added integer delta. + */ + class ZeroBound extends Bound, TBoundZero { override string toString() { result = "0" } override Expr getExpr(int delta) { result.(ConstantIntegerExpr).getIntValue() = delta } override Location getLocation() { result.hasLocationInfo("", 0, 0, 0, 0) } - } + } - /** - * A bound corresponding to the value of an SSA variable. - */ - class SsaBound extends Bound, TBoundSsa { + /** + * A bound corresponding to the value of an SSA variable. + */ + class SsaBound extends Bound, TBoundSsa { /** Gets the SSA variable that equals this bound. */ SsaVariable getSsa() { this = TBoundSsa(result) } @@ -84,17 +89,17 @@ module Bound Defs> { override Expr getExpr(int delta) { result = this.getSsa().getAUse() and delta = 0 } override Location getLocation() { result = this.getSsa().getLocation() } - } + } - /** - * A bound that corresponds to the value of a specific expression that might be - * interesting, but isn't otherwise represented by the value of an SSA variable. - */ - class ExprBound extends Bound, TBoundExpr { + /** + * A bound that corresponds to the value of a specific expression that might be + * interesting, but isn't otherwise represented by the value of an SSA variable. + */ + class ExprBound extends Bound, TBoundExpr { override string toString() { result = this.getExpr().toString() } override Expr getExpr(int delta) { this = TBoundExpr(result) and delta = 0 } override Location getLocation() { result = this.getExpr().getLocation() } - } + } }