Skip to content

Commit acb0554

Browse files
author
Benjamin Muskalla
committed
Extract inline flow test
1 parent d1a1f57 commit acb0554

File tree

3 files changed

+62
-28
lines changed

3 files changed

+62
-28
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import semmle.code.java.dataflow.DataFlow
2+
import semmle.code.java.dataflow.ExternalFlow
3+
import semmle.code.java.dataflow.TaintTracking
4+
import TestUtilities.InlineExpectationsTest
5+
6+
class DefaultValueFlowConf extends DataFlow::Configuration {
7+
DefaultValueFlowConf() { this = "qltest:defaultValueFlowConf" }
8+
9+
override predicate isSource(DataFlow::Node n) {
10+
n.asExpr().(MethodAccess).getMethod().hasName("source")
11+
}
12+
13+
override predicate isSink(DataFlow::Node n) {
14+
n.asExpr().(Argument).getCall().getCallee().hasName("sink")
15+
}
16+
}
17+
18+
class DefaultTaintFlowConf extends TaintTracking::Configuration {
19+
DefaultTaintFlowConf() { this = "qltest:defaultTaintFlowConf" }
20+
21+
override predicate isSource(DataFlow::Node n) {
22+
n.asExpr().(MethodAccess).getMethod().hasName("source")
23+
}
24+
25+
override predicate isSink(DataFlow::Node n) {
26+
n.asExpr().(Argument).getCall().getCallee().hasName("sink")
27+
}
28+
}
29+
30+
class InlineFlowTest extends InlineExpectationsTest {
31+
InlineFlowTest() { this = "HasFlowTest" }
32+
33+
override string getARelevantTag() { result = ["hasValueFlow", "hasTaintFlow"] }
34+
35+
override predicate hasActualResult(Location location, string element, string tag, string value) {
36+
tag = "hasValueFlow" and
37+
exists(DataFlow::Node src, DataFlow::Node sink | getValueFlowConfig().hasFlow(src, sink) |
38+
sink.getLocation() = location and
39+
element = sink.toString() and
40+
value = ""
41+
)
42+
or
43+
tag = "hasTaintFlow" and
44+
exists(DataFlow::Node src, DataFlow::Node sink |
45+
getTaintFlowConfig().hasFlow(src, sink) and not getValueFlowConfig().hasFlow(src, sink)
46+
|
47+
sink.getLocation() = location and
48+
element = sink.toString() and
49+
value = ""
50+
)
51+
}
52+
53+
DataFlow::Configuration getValueFlowConfig() { result = any(DefaultValueFlowConf config) }
54+
55+
DataFlow::Configuration getTaintFlowConfig() { result = any(DefaultTaintFlowConf config) }
56+
}
Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import java
22
import semmle.code.java.dataflow.DataFlow
33
import semmle.code.java.dataflow.TaintTracking
4-
import TestUtilities.InlineExpectationsTest
4+
import TestUtilities.InlineFlowTest
55

66
class TaintFlowConf extends TaintTracking::Configuration {
77
TaintFlowConf() { this = "qltest:dataflow:format" }
@@ -13,17 +13,6 @@ class TaintFlowConf extends TaintTracking::Configuration {
1313
override predicate isSink(DataFlow::Node n) { n instanceof DataFlow::ExprNode }
1414
}
1515

16-
class HasFlowTest extends InlineExpectationsTest {
17-
HasFlowTest() { this = "HasFlowTest" }
18-
19-
override string getARelevantTag() { result = ["hasTaintFlow"] }
20-
21-
override predicate hasActualResult(Location location, string element, string tag, string value) {
22-
tag = "hasTaintFlow" and
23-
exists(DataFlow::Node src, DataFlow::Node sink, TaintFlowConf conf | conf.hasFlow(src, sink) |
24-
sink.getLocation() = location and
25-
element = sink.toString() and
26-
value = ""
27-
)
28-
}
16+
class HasFlowTest extends InlineFlowTest {
17+
override DataFlow::Configuration getTaintFlowConfig() { result = any(TaintFlowConf config) }
2918
}

java/ql/test/library-tests/frameworks/apache-http/flow.ql

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import semmle.code.java.dataflow.TaintTracking
33
import semmle.code.java.dataflow.FlowSources
44
import semmle.code.java.security.XSS
55
import semmle.code.java.security.UrlRedirect
6-
import TestUtilities.InlineExpectationsTest
6+
import TestUtilities.InlineFlowTest
77

88
class Conf extends TaintTracking::Configuration {
99
Conf() { this = "qltest:frameworks:apache-http" }
@@ -23,17 +23,6 @@ class Conf extends TaintTracking::Configuration {
2323
}
2424
}
2525

26-
class HasFlowTest extends InlineExpectationsTest {
27-
HasFlowTest() { this = "HasFlowTest" }
28-
29-
override string getARelevantTag() { result = "hasTaintFlow" }
30-
31-
override predicate hasActualResult(Location location, string element, string tag, string value) {
32-
tag = "hasTaintFlow" and
33-
exists(DataFlow::Node src, DataFlow::Node sink, Conf conf | conf.hasFlow(src, sink) |
34-
sink.getLocation() = location and
35-
element = sink.toString() and
36-
value = ""
37-
)
38-
}
26+
class HasFlowTest extends InlineFlowTest {
27+
override DataFlow::Configuration getTaintFlowConfig() { result = any(Conf c) }
3928
}

0 commit comments

Comments
 (0)