1
+ /** Provides clases and methods shared by randomness-related queries. */
2
+
1
3
import java
2
4
import semmle.code.java.dataflow.DefUse
3
5
import semmle.code.java.dataflow.DataFlow6
@@ -89,6 +91,10 @@ private predicate safelySeeded(RValue use) {
89
91
)
90
92
}
91
93
94
+ /**
95
+ * Holds if predictable seed `source` is used to initialise a random-number generator
96
+ * used at `use`.
97
+ */
92
98
predicate unsafelySeeded ( RValue use , PredictableSeedExpr source ) {
93
99
isSeedingSource ( _, use , source ) and
94
100
not safelySeeded ( use )
@@ -131,6 +137,10 @@ private predicate isSeedingConstruction(ClassInstanceExpr c, Expr arg) {
131
137
c .getArgument ( 0 ) = arg
132
138
}
133
139
140
+ /**
141
+ * A constant, call to a `ReturnsPredictableExpr` method, or an array initialiser
142
+ * consisting entirely of the same.
143
+ */
134
144
class PredictableSeedExpr extends Expr {
135
145
PredictableSeedExpr ( ) {
136
146
this .( MethodAccess ) .getCallee ( ) instanceof ReturnsPredictableExpr
@@ -145,9 +155,15 @@ class PredictableSeedExpr extends Expr {
145
155
}
146
156
}
147
157
158
+ /**
159
+ * A method whose return value is predictable (not necessarily constant).
160
+ *
161
+ * Extend this class in order that all randomness-related queries should consider the result
162
+ * of a particular method predictable when noting bad RNG seeding and related issues.
163
+ */
148
164
abstract class ReturnsPredictableExpr extends Method { }
149
165
150
- class ReturnsSystemTime extends ReturnsPredictableExpr {
166
+ private class ReturnsSystemTime extends ReturnsPredictableExpr {
151
167
ReturnsSystemTime ( ) {
152
168
this .getDeclaringType ( ) .hasQualifiedName ( "java.lang" , "System" ) and
153
169
this .hasName ( "currentTimeMillis" )
0 commit comments