Skip to content

Commit c67b984

Browse files
committed
Refactor RandomQuery.qll
1 parent 2698b61 commit c67b984

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java
44
import semmle.code.java.dataflow.DefUse
5-
import semmle.code.java.dataflow.DataFlow6
5+
import semmle.code.java.dataflow.DataFlow
66
import RandomDataSource
77

88
/**
@@ -29,20 +29,18 @@ private predicate isSeeded(RValue use) {
2929
)
3030
}
3131

32-
private class PredictableSeedFlowConfiguration extends DataFlow6::Configuration {
33-
PredictableSeedFlowConfiguration() { this = "Random::PredictableSeedFlowConfiguration" }
32+
private module PredictableSeedFlowConfig implements DataFlow::ConfigSig {
33+
predicate isSource(DataFlow::Node source) { source.asExpr() instanceof PredictableSeedExpr }
3434

35-
override predicate isSource(DataFlow6::Node source) {
36-
source.asExpr() instanceof PredictableSeedExpr
37-
}
38-
39-
override predicate isSink(DataFlow6::Node sink) { isSeeding(sink.asExpr(), _) }
35+
predicate isSink(DataFlow::Node sink) { isSeeding(sink.asExpr(), _) }
4036

41-
override predicate isAdditionalFlowStep(DataFlow6::Node node1, DataFlow6::Node node2) {
37+
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
4238
predictableCalcStep(node1.asExpr(), node2.asExpr())
4339
}
4440
}
4541

42+
private module PredictableSeedFlow = DataFlow::Global<PredictableSeedFlowConfig>;
43+
4644
private predicate predictableCalcStep(Expr e1, Expr e2) {
4745
e2.(BinaryExpr).hasOperands(e1, any(PredictableSeedExpr p))
4846
or
@@ -81,7 +79,7 @@ private predicate predictableCalcStep(Expr e1, Expr e2) {
8179
private predicate safelySeeded(RValue use) {
8280
exists(Expr arg |
8381
isSeeding(arg, use) and
84-
not exists(PredictableSeedFlowConfiguration conf | conf.hasFlowToExpr(arg))
82+
not PredictableSeedFlow::flowToExpr(arg)
8583
)
8684
or
8785
exists(GetRandomData da, RValue seeduse |
@@ -118,9 +116,7 @@ private predicate isSeeding(Expr arg, RValue use) {
118116

119117
private predicate isSeedingSource(Expr arg, RValue use, Expr source) {
120118
isSeeding(arg, use) and
121-
exists(PredictableSeedFlowConfiguration conf |
122-
conf.hasFlow(DataFlow6::exprNode(source), DataFlow6::exprNode(arg))
123-
)
119+
PredictableSeedFlow::flow(DataFlow::exprNode(source), DataFlow::exprNode(arg))
124120
}
125121

126122
private predicate isRandomSeeding(MethodAccess m, Expr arg) {

0 commit comments

Comments
 (0)