Skip to content

Commit 66010b5

Browse files
committed
Java: Switch helper flow from Global to SimpleGlobal in StaticInitializationVectorQuery.
1 parent 2fa8c2f commit 66010b5

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,29 @@ private class ArrayUpdate extends Expr {
8080
Expr getArray() { result = array }
8181
}
8282

83-
/**
84-
* A config that tracks dataflow from creating an array to an operation that updates it.
85-
*/
86-
private module ArrayUpdateConfig implements DataFlow::ConfigSig {
87-
predicate isSource(DataFlow::Node source) { source.asExpr() instanceof StaticByteArrayCreation }
88-
89-
predicate isSink(DataFlow::Node sink) { sink.asExpr() = any(ArrayUpdate upd).getArray() }
83+
private predicate arrayUpdateSrc(DataFlow::Node source) {
84+
source.asExpr() instanceof StaticByteArrayCreation
85+
}
9086

91-
predicate isBarrierOut(DataFlow::Node node) { isSink(node) }
87+
private predicate arrayUpdateSink(DataFlow::Node sink) {
88+
sink.asExpr() = any(ArrayUpdate upd).getArray()
9289
}
9390

94-
private module ArrayUpdateFlow = DataFlow::Global<ArrayUpdateConfig>;
91+
private module ArrayUpdateFlowFwd = DataFlow::SimpleGlobal<arrayUpdateSrc/1>;
92+
93+
private module ArrayUpdateFlow = ArrayUpdateFlowFwd::Graph<arrayUpdateSink/1>;
94+
95+
private predicate arrayReachesUpdate(StaticByteArrayCreation array) {
96+
exists(ArrayUpdateFlow::PathNode src | src.isSource() and src.getNode().asExpr() = array)
97+
}
9598

9699
/**
97100
* A source that defines an array that doesn't get updated.
98101
*/
99102
private class StaticInitializationVectorSource extends DataFlow::Node {
100103
StaticInitializationVectorSource() {
101104
exists(StaticByteArrayCreation array | array = this.asExpr() |
102-
not ArrayUpdateFlow::flow(DataFlow::exprNode(array), _) and
105+
not arrayReachesUpdate(array) and
103106
// Reduce FPs from utility methods that return an empty array in an exceptional case
104107
not exists(ReturnStmt ret |
105108
array.getADimension().(CompileTimeConstantExpr).getIntValue() = 0 and

0 commit comments

Comments
 (0)