Skip to content

Commit 437b2c1

Browse files
committed
Java: Cosmetic changes and missing overrides.
1 parent 0647743 commit 437b2c1

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

java/ql/src/Security/CWE/CWE-129/ArraySizing.qll

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,25 @@ private import BoundingChecks
77
* If the `Array` accessed by the `ArrayAccess` is a fixed size, return the array size.
88
*/
99
int fixedArraySize(ArrayAccess arrayAccess) {
10-
result = arrayAccess
11-
.getArray()
12-
.(VarAccess)
13-
.getVariable()
14-
.getAnAssignedValue()
15-
.(ArrayCreationExpr)
16-
.getFirstDimensionSize()
10+
exists(Variable v |
11+
v.getAnAccess() = arrayAccess.getArray() and
12+
result = v.getAnAssignedValue().(ArrayCreationExpr).getFirstDimensionSize()
13+
)
1714
}
1815

1916
/**
2017
* Holds if an `ArrayIndexOutOfBoundsException` is ever caught.
2118
*/
2219
private predicate arrayIndexOutOfBoundExceptionCaught(ArrayAccess arrayAccess) {
23-
exists(TryStmt ts, CatchClause cc |
20+
exists(TryStmt ts, CatchClause cc, RefType exc |
2421
(
2522
ts.getBlock().getAChild*() = arrayAccess.getEnclosingStmt() or
2623
ts.getAResourceDecl().getAChild*() = arrayAccess.getEnclosingStmt() or
2724
ts.getAResourceExpr().getAChildExpr*() = arrayAccess
2825
) and
29-
cc = ts.getACatchClause()
30-
|
31-
cc
32-
.getVariable()
33-
.getType()
34-
.(RefType)
35-
.hasQualifiedName("java.lang", "ArrayIndexOutOfBoundsException")
26+
cc = ts.getACatchClause() and
27+
exc = cc.getVariable().getType() and
28+
exc.hasQualifiedName("java.lang", "ArrayIndexOutOfBoundsException")
3629
)
3730
}
3831

@@ -144,22 +137,22 @@ class RandomValueFlowSource extends BoundedFlowSource {
144137
)
145138
}
146139

147-
int lowerBound() {
140+
override int lowerBound() {
148141
// If this call is to `nextInt()`, the lower bound is zero.
149142
this.asExpr().(MethodAccess).getCallee().hasName("nextInt") and
150143
this.asExpr().(MethodAccess).getNumArgument() = 1 and
151144
result = 0
152145
}
153146

154-
int upperBound() {
147+
override int upperBound() {
155148
// If this call specified an argument to `nextInt()`, and that argument is a compile time constant,
156149
// it forms the upper bound.
157150
this.asExpr().(MethodAccess).getCallee().hasName("nextInt") and
158151
this.asExpr().(MethodAccess).getNumArgument() = 1 and
159152
result = this.asExpr().(MethodAccess).getArgument(0).(CompileTimeConstantExpr).getIntValue()
160153
}
161154

162-
string getDescription() { result = "Random value" }
155+
override string getDescription() { result = "Random value" }
163156
}
164157

165158
/**
@@ -168,11 +161,11 @@ class RandomValueFlowSource extends BoundedFlowSource {
168161
class NumericLiteralFlowSource extends BoundedFlowSource {
169162
NumericLiteralFlowSource() { exists(this.asExpr().(CompileTimeConstantExpr).getIntValue()) }
170163

171-
int lowerBound() { result = this.asExpr().(CompileTimeConstantExpr).getIntValue() }
164+
override int lowerBound() { result = this.asExpr().(CompileTimeConstantExpr).getIntValue() }
172165

173-
int upperBound() { result = this.asExpr().(CompileTimeConstantExpr).getIntValue() }
166+
override int upperBound() { result = this.asExpr().(CompileTimeConstantExpr).getIntValue() }
174167

175-
string getDescription() {
168+
override string getDescription() {
176169
result = "Literal value " + this.asExpr().(CompileTimeConstantExpr).getIntValue()
177170
}
178171
}

0 commit comments

Comments
 (0)