Skip to content

Commit bbd3ecb

Browse files
committed
Add docs to RandomQuery.qll
1 parent e661fc0 commit bbd3ecb

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

java/ql/src/semmle/code/java/security/RandomQuery.qll

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/** Provides clases and methods shared by randomness-related queries. */
2+
13
import java
24
import semmle.code.java.dataflow.DefUse
35
import 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+
*/
9298
predicate 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+
*/
134144
class 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+
*/
148164
abstract 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

Comments
 (0)