@@ -2,43 +2,17 @@ import java
2
2
import semmle.code.java.dataflow.DefUse
3
3
import semmle.code.java.dataflow.DataFlow
4
4
5
- /**
6
- * A class with methods that generate random data.
7
- */
8
- abstract class RandomNumberGenerator extends RefType { }
9
-
10
5
/**
11
6
* The `java.security.SecureRandom` class.
12
7
*/
13
- class SecureRandomNumberGenerator extends RandomNumberGenerator {
8
+ class SecureRandomNumberGenerator extends RefType {
14
9
SecureRandomNumberGenerator ( ) { this .hasQualifiedName ( "java.security" , "SecureRandom" ) }
15
10
}
16
11
17
- /**
18
- * The `java.util.Random` class or any of its subtypes, including `java.security.SecureRandom`.
19
- */
20
- class StdlibRandom extends RandomNumberGenerator {
21
- StdlibRandom ( ) { this .getAnAncestor ( ) .hasQualifiedName ( "java.util" , "Random" ) }
22
- }
23
-
24
- /**
25
- * The `org.apache.commons.lang3.RandomUtils` class.
26
- */
27
- class ApacheRandomUtils extends RandomNumberGenerator {
28
- ApacheRandomUtils ( ) { this .hasQualifiedName ( "org.apache.commons.lang3" , "RandomUtils" ) }
29
- }
30
-
31
12
/**
32
13
* A method access that returns random data or writes random data to an argument.
33
14
*/
34
15
abstract class RandomDataSource extends MethodAccess {
35
- RandomDataSource ( ) {
36
- exists ( Method m | m = this .getMethod ( ) |
37
- m .getName ( ) .matches ( "next%" ) and
38
- m .getDeclaringType ( ) instanceof RandomNumberGenerator
39
- )
40
- }
41
-
42
16
/**
43
17
* Gets the integer lower bound, inclusive, of the values returned by this call,
44
18
* if applicable to this method's type and a constant bound is known.
@@ -85,7 +59,8 @@ class StdlibRandomSource extends RandomDataSource {
85
59
86
60
StdlibRandomSource ( ) {
87
61
m = this .getMethod ( ) and
88
- m .getDeclaringType ( ) instanceof StdlibRandom
62
+ m .getName ( ) .matches ( "next%" ) and
63
+ m .getDeclaringType ( ) .getAnAncestor ( ) .hasQualifiedName ( "java.util" , "Random" )
89
64
}
90
65
91
66
// Note for the following bounds functions: `java.util.Random` only defines no-arg versions
@@ -146,7 +121,8 @@ class ApacheCommonsRandomSource extends RandomDataSource {
146
121
147
122
ApacheCommonsRandomSource ( ) {
148
123
m = this .getMethod ( ) and
149
- m .getDeclaringType ( ) instanceof ApacheRandomUtils
124
+ m .getName ( ) .matches ( "next%" ) and
125
+ m .getDeclaringType ( ) .hasQualifiedName ( "org.apache.commons.lang3" , "RandomUtils" )
150
126
}
151
127
152
128
override Expr getLowerBoundExpr ( ) {
0 commit comments