1
+ /**
2
+ * Common definitions for the unbounded allocation queries.
3
+ */
4
+
1
5
import semmle.code.java.dataflow.RangeAnalysis
2
6
import semmle.code.java.dataflow.FlowSteps
3
7
import semmle.code.java.dataflow.DataFlow
4
8
import semmle.code.java.dataflow.TaintTracking
5
9
10
+ /** A sink where memory is allocated. */
6
11
class AllocationSink extends DataFlow:: Node {
7
12
AllocationSink ( ) {
8
13
this .asExpr ( ) = any ( ArrayCreationExpr a ) .getADimension ( )
@@ -14,11 +19,13 @@ class AllocationSink extends DataFlow::Node {
14
19
}
15
20
}
16
21
22
+ /** A callable that allocates memory. */
17
23
abstract class AllocatingCallable extends Callable {
24
+ /** Returns the parameter index controlling the size of the allocated memory. */
18
25
abstract int getParam ( ) ;
19
26
}
20
27
21
- class AtomicArrayConstructor extends AllocatingCallable , Constructor {
28
+ private class AtomicArrayConstructor extends AllocatingCallable , Constructor {
22
29
AtomicArrayConstructor ( ) {
23
30
this
24
31
.getDeclaringType ( )
@@ -30,7 +37,7 @@ class AtomicArrayConstructor extends AllocatingCallable, Constructor {
30
37
override int getParam ( ) { result = 0 }
31
38
}
32
39
33
- class ListConstructor extends AllocatingCallable , Constructor {
40
+ private class ListConstructor extends AllocatingCallable , Constructor {
34
41
ListConstructor ( ) {
35
42
this .getDeclaringType ( ) .hasQualifiedName ( "java.util" , [ "ArrayList" , "Vector" ] ) and
36
43
this .getParameterType ( 0 ) instanceof IntegralType
@@ -39,7 +46,7 @@ class ListConstructor extends AllocatingCallable, Constructor {
39
46
override int getParam ( ) { result = 0 }
40
47
}
41
48
42
- class ReadMethod extends TaintPreservingCallable {
49
+ private class ReadMethod extends TaintPreservingCallable {
43
50
ReadMethod ( ) {
44
51
this .getDeclaringType ( ) .hasQualifiedName ( "java.io" , "ObjectInputStream" ) and
45
52
this .getName ( ) .matches ( "read%" )
@@ -48,7 +55,7 @@ class ReadMethod extends TaintPreservingCallable {
48
55
override predicate returnsTaintFrom ( int arg ) { arg = - 1 }
49
56
}
50
57
51
- class ArithmeticStep extends TaintTracking:: AdditionalTaintStep {
58
+ private class ArithmeticStep extends TaintTracking:: AdditionalTaintStep {
52
59
override predicate step ( DataFlow:: Node src , DataFlow:: Node sink ) {
53
60
exists ( BinaryExpr binex | sink .asExpr ( ) = binex and src .asExpr ( ) = binex .getAnOperand ( ) |
54
61
binex instanceof AddExpr
@@ -71,4 +78,5 @@ class ArithmeticStep extends TaintTracking::AdditionalTaintStep {
71
78
}
72
79
}
73
80
81
+ /** Holds if `e` has a known upper bound. */
74
82
predicate hasUpperBound ( Expr e ) { bounded ( e , any ( ZeroBound z ) , _, true , _) }
0 commit comments