1+ /** Provides clases and methods shared by randomness-related queries. */
2+
13import java
24import semmle.code.java.dataflow.DefUse
35import semmle.code.java.dataflow.DataFlow6
@@ -89,6 +91,10 @@ private predicate safelySeeded(RValue use) {
8991 )
9092}
9193
94+ /**
95+ * Holds if predictable seed `source` is used to initialise a random-number generator
96+ * used at `use`.
97+ */
9298predicate unsafelySeeded ( RValue use , PredictableSeedExpr source ) {
9399 isSeedingSource ( _, use , source ) and
94100 not safelySeeded ( use )
@@ -131,6 +137,10 @@ private predicate isSeedingConstruction(ClassInstanceExpr c, Expr arg) {
131137 c .getArgument ( 0 ) = arg
132138}
133139
140+ /**
141+ * A constant, call to a `ReturnsPredictableExpr` method, or an array initialiser
142+ * consisting entirely of the same.
143+ */
134144class PredictableSeedExpr extends Expr {
135145 PredictableSeedExpr ( ) {
136146 this .( MethodAccess ) .getCallee ( ) instanceof ReturnsPredictableExpr
@@ -145,9 +155,15 @@ class PredictableSeedExpr extends Expr {
145155 }
146156}
147157
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+ */
148164abstract class ReturnsPredictableExpr extends Method { }
149165
150- class ReturnsSystemTime extends ReturnsPredictableExpr {
166+ private class ReturnsSystemTime extends ReturnsPredictableExpr {
151167 ReturnsSystemTime ( ) {
152168 this .getDeclaringType ( ) .hasQualifiedName ( "java.lang" , "System" ) and
153169 this .hasName ( "currentTimeMillis" )
0 commit comments