Skip to content

Commit 71f8ccf

Browse files
authored
Merge pull request #15654 from aschackmull/java/static-init-vec-query-perf
Java: Switch helper flow from Global to SimpleGlobal in StaticInitializationVectorQuery.
2 parents f072e41 + 5a348a5 commit 71f8ccf

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

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

+13-10
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

shared/typetracking/codeql/typetracking/internal/TypeTrackingImpl.qll

+11-9
Original file line numberDiff line numberDiff line change
@@ -785,24 +785,26 @@ module TypeTracking<TypeTrackingInput I> {
785785
)
786786
}
787787

788+
private Node getNodeMid(PathNodeFwd n) { n = TPathNodeMid(result, _) }
789+
790+
private Node getNodeSink(PathNodeFwd n) { n = TPathNodeSink(result) }
791+
788792
private predicate edgeCand(PathNodeFwd n1, PathNodeFwd n2) {
789793
exists(PathNodeFwd tgt |
790-
edgeCand(n1.getNode(), n1.getTypeTracker(), tgt.getNode(), tgt.getTypeTracker())
794+
edgeCand(getNodeMid(n1), n1.getTypeTracker(), getNodeMid(tgt), tgt.getTypeTracker())
791795
|
792796
n2 = tgt
793797
or
794-
n2 = TPathNodeSink(tgt.getNode()) and tgt.getTypeTracker().end()
798+
n2 = TPathNodeSink(getNodeMid(tgt)) and tgt.getTypeTracker().end()
795799
)
796800
or
797801
n1.getTypeTracker().end() and
798-
flowsTo(n1.getNode(), n2.getNode()) and
799-
n1.getNode() != n2.getNode() and
800-
n2 instanceof TPathNodeSink
802+
flowsTo(getNodeMid(n1), getNodeSink(n2)) and
803+
getNodeMid(n1) != getNodeSink(n2)
801804
or
802-
sourceSimpleLocalSmallSteps(n1.getNode(), n2.getNode()) and
803-
n1.getNode() != n2.getNode() and
804-
n1.isSource() and
805-
n2.isSink()
805+
sourceSimpleLocalSmallSteps(n1.getNode(), getNodeSink(n2)) and
806+
n1.getNode() != getNodeSink(n2) and
807+
n1.isSource()
806808
}
807809

808810
private predicate reachRev(PathNodeFwd n) {

0 commit comments

Comments
 (0)