@@ -2,43 +2,17 @@ import java
22import semmle.code.java.dataflow.DefUse
33import semmle.code.java.dataflow.DataFlow
44
5- /**
6- * A class with methods that generate random data.
7- */
8- abstract class RandomNumberGenerator extends RefType { }
9-
105/**
116 * The `java.security.SecureRandom` class.
127 */
13- class SecureRandomNumberGenerator extends RandomNumberGenerator {
8+ class SecureRandomNumberGenerator extends RefType {
149 SecureRandomNumberGenerator ( ) { this .hasQualifiedName ( "java.security" , "SecureRandom" ) }
1510}
1611
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-
3112/**
3213 * A method access that returns random data or writes random data to an argument.
3314 */
3415abstract 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-
4216 /**
4317 * Gets the integer lower bound, inclusive, of the values returned by this call,
4418 * if applicable to this method's type and a constant bound is known.
@@ -85,7 +59,8 @@ class StdlibRandomSource extends RandomDataSource {
8559
8660 StdlibRandomSource ( ) {
8761 m = this .getMethod ( ) and
88- m .getDeclaringType ( ) instanceof StdlibRandom
62+ m .getName ( ) .matches ( "next%" ) and
63+ m .getDeclaringType ( ) .getAnAncestor ( ) .hasQualifiedName ( "java.util" , "Random" )
8964 }
9065
9166 // Note for the following bounds functions: `java.util.Random` only defines no-arg versions
@@ -146,7 +121,8 @@ class ApacheCommonsRandomSource extends RandomDataSource {
146121
147122 ApacheCommonsRandomSource ( ) {
148123 m = this .getMethod ( ) and
149- m .getDeclaringType ( ) instanceof ApacheRandomUtils
124+ m .getName ( ) .matches ( "next%" ) and
125+ m .getDeclaringType ( ) .hasQualifiedName ( "org.apache.commons.lang3" , "RandomUtils" )
150126 }
151127
152128 override Expr getLowerBoundExpr ( ) {
0 commit comments