Skip to content

Commit bb0ec46

Browse files
committed
Java: Update tests.
1 parent 00a273b commit bb0ec46

File tree

5 files changed

+73
-36
lines changed

5 files changed

+73
-36
lines changed

java/ql/test/TestUtilities/InlineFlowTest.qll

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ private predicate defaultSource(DataFlow::Node src) {
4747
src.asExpr().(MethodAccess).getMethod().getName() = ["source", "taint"]
4848
}
4949

50+
private module DefaultFlowConf implements DataFlow::ConfigSig {
51+
predicate isSource(DataFlow::Node n) { defaultSource(n) }
52+
53+
predicate isSink(DataFlow::Node n) {
54+
exists(MethodAccess ma | ma.getMethod().hasName("sink") | n.asExpr() = ma.getAnArgument())
55+
}
56+
57+
int fieldFlowBranchLimit() { result = 1000 }
58+
}
59+
60+
private module DefaultValueFlow = DataFlow::Make<DefaultFlowConf>;
61+
62+
private module DefaultTaintFlow = TaintTracking::Make<DefaultFlowConf>;
63+
5064
class DefaultValueFlowConf extends DataFlow::Configuration {
5165
DefaultValueFlowConf() { this = "qltest:defaultValueFlowConf" }
5266

@@ -76,26 +90,47 @@ private string getSourceArgString(DataFlow::Node src) {
7690
src.asExpr().(MethodAccess).getAnArgument().(StringLiteral).getValue() = result
7791
}
7892

93+
abstract class EnableLegacyConfiguration extends Unit { }
94+
7995
class InlineFlowTest extends InlineExpectationsTest {
8096
InlineFlowTest() { this = "HasFlowTest" }
8197

8298
override string getARelevantTag() { result = ["hasValueFlow", "hasTaintFlow"] }
8399

84100
override predicate hasActualResult(Location location, string element, string tag, string value) {
85-
tag = "hasValueFlow" and
86-
exists(DataFlow::Node src, DataFlow::Node sink | getValueFlowConfig().hasFlow(src, sink) |
87-
sink.getLocation() = location and
88-
element = sink.toString() and
89-
if exists(getSourceArgString(src)) then value = getSourceArgString(src) else value = ""
90-
)
91-
or
92-
tag = "hasTaintFlow" and
93-
exists(DataFlow::Node src, DataFlow::Node sink |
94-
getTaintFlowConfig().hasFlow(src, sink) and not getValueFlowConfig().hasFlow(src, sink)
95-
|
96-
sink.getLocation() = location and
97-
element = sink.toString() and
98-
if exists(getSourceArgString(src)) then value = getSourceArgString(src) else value = ""
101+
if exists(EnableLegacyConfiguration e)
102+
then
103+
tag = "hasValueFlow" and
104+
exists(DataFlow::Node src, DataFlow::Node sink | getValueFlowConfig().hasFlow(src, sink) |
105+
sink.getLocation() = location and
106+
element = sink.toString() and
107+
if exists(getSourceArgString(src)) then value = getSourceArgString(src) else value = ""
108+
)
109+
or
110+
tag = "hasTaintFlow" and
111+
exists(DataFlow::Node src, DataFlow::Node sink |
112+
getTaintFlowConfig().hasFlow(src, sink) and not getValueFlowConfig().hasFlow(src, sink)
113+
|
114+
sink.getLocation() = location and
115+
element = sink.toString() and
116+
if exists(getSourceArgString(src)) then value = getSourceArgString(src) else value = ""
117+
)
118+
else (
119+
tag = "hasValueFlow" and
120+
exists(DataFlow::Node src, DataFlow::Node sink | DefaultValueFlow::hasFlow(src, sink) |
121+
sink.getLocation() = location and
122+
element = sink.toString() and
123+
if exists(getSourceArgString(src)) then value = getSourceArgString(src) else value = ""
124+
)
125+
or
126+
tag = "hasTaintFlow" and
127+
exists(DataFlow::Node src, DataFlow::Node sink |
128+
DefaultTaintFlow::hasFlow(src, sink) and not DefaultValueFlow::hasFlow(src, sink)
129+
|
130+
sink.getLocation() = location and
131+
element = sink.toString() and
132+
if exists(getSourceArgString(src)) then value = getSourceArgString(src) else value = ""
133+
)
99134
)
100135
}
101136

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import java
22
import semmle.code.java.dataflow.DataFlow
33
import TestUtilities.InlineFlowTest
4-
5-
class HasFlowTest extends InlineFlowTest {
6-
override DataFlow::Configuration getTaintFlowConfig() { none() }
7-
}
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import java
22
import semmle.code.java.dataflow.DataFlow
33
import DataFlow
4-
import PartialPathGraph
54

6-
class Conf extends Configuration {
7-
Conf() { this = "partial flow" }
5+
module Config implements ConfigSig {
6+
predicate isSource(Node n) { n.asExpr().(MethodAccess).getMethod().hasName("src") }
87

9-
override predicate isSource(Node n) { n.asExpr().(MethodAccess).getMethod().hasName("src") }
8+
predicate isSink(Node n) { n.asExpr().(Argument).getCall().getCallee().hasName("sink") }
9+
}
1010

11-
override predicate isSink(Node n) { n.asExpr().(Argument).getCall().getCallee().hasName("sink") }
11+
int explorationLimit() { result = 10 }
1212

13-
override int explorationLimit() { result = 10 }
14-
}
13+
module PartialFlow = Make<Config>::FlowExploration<explorationLimit/0>;
14+
15+
import PartialFlow::PartialPathGraph
1516

16-
from PartialPathNode n, int dist
17-
where any(Conf c).hasPartialFlow(_, n, dist)
17+
from PartialFlow::PartialPathNode n, int dist
18+
where PartialFlow::hasPartialFlow(_, n, dist)
1819
select dist, n
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import java
22
import semmle.code.java.dataflow.DataFlow
33
import DataFlow
4-
import PartialPathGraph
54

6-
class Conf extends Configuration {
7-
Conf() { this = "partial flow" }
5+
module Config implements ConfigSig {
6+
predicate isSource(Node n) { n.asExpr().(MethodAccess).getMethod().hasName("src") }
87

9-
override predicate isSource(Node n) { n.asExpr().(MethodAccess).getMethod().hasName("src") }
8+
predicate isSink(Node n) { n.asExpr().(Argument).getCall().getCallee().hasName("sink") }
9+
}
1010

11-
override predicate isSink(Node n) { n.asExpr().(Argument).getCall().getCallee().hasName("sink") }
11+
int explorationLimit() { result = 10 }
1212

13-
override int explorationLimit() { result = 10 }
14-
}
13+
module PartialFlow = Make<Config>::FlowExploration<explorationLimit/0>;
14+
15+
import PartialFlow::PartialPathGraph
1516

16-
from PartialPathNode n, int dist
17-
where any(Conf c).hasPartialFlowRev(n, _, dist)
17+
from PartialFlow::PartialPathNode n, int dist
18+
where PartialFlow::hasPartialFlowRev(n, _, dist)
1819
select dist, n

java/ql/test/library-tests/frameworks/android/external-storage/test.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import semmle.code.java.dataflow.DataFlow
33
import semmle.code.java.dataflow.FlowSources
44
import TestUtilities.InlineFlowTest
55

6+
class EnableLegacy extends EnableLegacyConfiguration {
7+
EnableLegacy() { exists(this) }
8+
}
9+
610
class Conf extends TaintTracking::Configuration {
711
Conf() { this = "test:AndroidExternalFlowConf" }
812

0 commit comments

Comments
 (0)