Skip to content

Commit acb5c0e

Browse files
committed
missed changes
1 parent 6042ade commit acb5c0e

4 files changed

Lines changed: 45 additions & 56 deletions

File tree

csharp/ql/lib/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies:
99
codeql/controlflow: ${workspace}
1010
codeql/dataflow: ${workspace}
1111
codeql/mad: ${workspace}
12+
codeql/rangeanalysis: ${workspace}
1213
codeql/ssa: ${workspace}
1314
codeql/threat-models: ${workspace}
1415
codeql/tutorial: ${workspace}

csharp/ql/lib/semmle/code/csharp/dataflow/Bound.qll

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,31 @@
44
overlay[local?]
55
module;
66

7+
private import csharp as CS
78
private import internal.rangeanalysis.BoundSpecific
9+
private import internal.rangeanalysis.BoundSpecific as BoundSpecific
10+
private import codeql.rangeanalysis.Bound as SharedBound
811

9-
private newtype TBound =
10-
TBoundZero() or
11-
TBoundSsa(SsaVariable v) { v.getSourceVariable().getType() instanceof IntegralType } or
12-
TBoundExpr(Expr e) {
13-
interestingExprBound(e) and
14-
not exists(SsaVariable v | e = v.getAUse())
15-
}
12+
private module BoundImpl = SharedBound::Bound<CS::Location, BoundSpecific::BoundDefs>;
1613

1714
/**
1815
* A bound that may be inferred for an expression plus/minus an integer delta.
1916
*/
20-
abstract class Bound extends TBound {
21-
/** Gets a textual representation of this bound. */
22-
abstract string toString();
23-
24-
/** Gets an expression that equals this bound plus `delta`. */
25-
abstract Expr getExpr(int delta);
26-
27-
/** Gets an expression that equals this bound. */
28-
Expr getExpr() { result = this.getExpr(0) }
29-
30-
/** Gets the location of this bound. */
31-
abstract Location getLocation();
32-
}
17+
class Bound = BoundImpl::Bound;
3318

3419
/**
3520
* The bound that corresponds to the integer 0. This is used to represent all
3621
* integer bounds as bounds are always accompanied by an added integer delta.
3722
*/
38-
class ZeroBound extends Bound, TBoundZero {
39-
override string toString() { result = "0" }
40-
41-
override Expr getExpr(int delta) { result.(ConstantIntegerExpr).getIntValue() = delta }
42-
43-
override Location getLocation() { result.hasLocationInfo("", 0, 0, 0, 0) }
44-
}
23+
class ZeroBound = BoundImpl::ZeroBound;
4524

4625
/**
4726
* A bound corresponding to the value of an SSA variable.
4827
*/
49-
class SsaBound extends Bound, TBoundSsa {
50-
/** Gets the SSA variable that equals this bound. */
51-
SsaVariable getSsa() { this = TBoundSsa(result) }
52-
53-
override string toString() { result = this.getSsa().toString() }
54-
55-
override Expr getExpr(int delta) { result = this.getSsa().getAUse() and delta = 0 }
56-
57-
override Location getLocation() { result = this.getSsa().getLocation() }
58-
}
28+
class SsaBound = BoundImpl::SsaBound;
5929

6030
/**
6131
* A bound that corresponds to the value of a specific expression that might be
6232
* interesting, but isn't otherwise represented by the value of an SSA variable.
6333
*/
64-
class ExprBound extends Bound, TBoundExpr {
65-
override string toString() { result = this.getExpr().toString() }
66-
67-
override Expr getExpr(int delta) { this = TBoundExpr(result) and delta = 0 }
68-
69-
override Location getLocation() { result = this.getExpr().getLocation() }
70-
}
34+
class ExprBound = BoundImpl::ExprBound;

csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/BoundSpecific.qll

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,26 @@ private import semmle.code.csharp.dataflow.SSA::Ssa as Ssa
77
private import semmle.code.csharp.dataflow.internal.rangeanalysis.ConstantUtils as CU
88
private import semmle.code.csharp.dataflow.internal.rangeanalysis.RangeUtils as RU
99
private import semmle.code.csharp.dataflow.internal.rangeanalysis.SsaUtils as SU
10+
private import codeql.rangeanalysis.Bound as SharedBound
1011

11-
class SsaVariable = SU::SsaVariable;
12+
/** Holds if `e` is a bound expression and it is not an SSA variable read. */
1213

13-
class Expr = CS::ControlFlowNodes::ExprNode;
1414

15-
class Location = CS::Location;
15+
module BoundDefs implements SharedBound::BoundDefinitions<CS::Location> {
16+
class Type = CS::Type;
1617

17-
class IntegralType = CS::IntegralType;
18+
class SsaVariable = SU::SsaVariable;
19+
20+
class SsaSourceVariable = Ssa::SourceVariable;
1821

19-
class ConstantIntegerExpr = CU::ConstantIntegerExpr;
22+
class Expr = CS::ControlFlowNodes::ExprNode;
2023

21-
/** Holds if `e` is a bound expression and it is not an SSA variable read. */
22-
predicate interestingExprBound(Expr e) { CU::systemArrayLengthAccess(e.getExpr()) }
24+
class IntegralType = CS::IntegralType;
25+
26+
class ConstantIntegerExpr = CU::ConstantIntegerExpr;
27+
28+
/** Holds if `e` is a bound expression and it is not an SSA variable read. */
29+
predicate interestingExprBound(Expr e) {
30+
CU::systemArrayLengthAccess(e.getExpr())
31+
}
32+
}

java/ql/lib/semmle/code/java/dataflow/Bound.qll

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,26 @@ private import java as J
88
private import internal.rangeanalysis.BoundSpecific as BoundSpecific
99
private import codeql.rangeanalysis.Bound as SharedBound
1010

11-
module BoundInstantiation = SharedBound::Bound<J::Location, BoundSpecific::BoundDefs>;
11+
private module BoundImpl = SharedBound::Bound<J::Location, BoundSpecific::BoundDefs>;
1212

13-
class Bound = BoundInstantiation::Bound;
13+
/**
14+
* A bound that may be inferred for an expression plus/minus an integer delta.
15+
*/
16+
class Bound = BoundImpl::Bound;
1417

15-
class ZeroBound = BoundInstantiation::ZeroBound;
18+
/**
19+
* The bound that corresponds to the integer 0. This is used to represent all
20+
* integer bounds as bounds are always accompanied by an added integer delta.
21+
*/
22+
class ZeroBound = BoundImpl::ZeroBound;
1623

17-
class SsaBound = BoundInstantiation::SsaBound;
24+
/**
25+
* A bound corresponding to the value of an SSA variable.
26+
*/
27+
class SsaBound = BoundImpl::SsaBound;
1828

19-
class ExprBound = BoundInstantiation::ExprBound;
29+
/**
30+
* A bound that corresponds to the value of a specific expression that might be
31+
* interesting, but isn't otherwise represented by the value of an SSA variable.
32+
*/
33+
class ExprBound = BoundImpl::ExprBound;

0 commit comments

Comments
 (0)