Skip to content

Commit c11da5b

Browse files
committed
Make taint tracking tests use InlineFlowTest
1 parent 663fb2c commit c11da5b

21 files changed

Lines changed: 277 additions & 522 deletions

File tree

go/ql/test/experimental/frameworks/CleverGo/TaintTracking.go

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,4 @@
11
import go
2-
import TestUtilities.InlineExpectationsTest
32
import experimental.frameworks.CleverGo
4-
5-
class Configuration extends TaintTracking::Configuration {
6-
Configuration() { this = "test-configuration" }
7-
8-
override predicate isSource(DataFlow::Node source) {
9-
exists(Function fn | fn.hasQualifiedName(_, "source") | source = fn.getACall().getResult())
10-
}
11-
12-
override predicate isSink(DataFlow::Node sink) {
13-
exists(Function fn | fn.hasQualifiedName(_, "sink") | sink = fn.getACall().getAnArgument())
14-
}
15-
}
16-
17-
module TaintTrackingTest implements TestSig {
18-
string getARelevantTag() { result = "taintSink" }
19-
20-
predicate hasActualResult(Location location, string element, string tag, string value) {
21-
tag = "taintSink" and
22-
exists(DataFlow::Node sink | any(Configuration c).hasFlow(_, sink) |
23-
element = sink.toString() and
24-
value = "" and
25-
sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
26-
location.getStartColumn(), location.getEndLine(), location.getEndColumn())
27-
)
28-
}
29-
}
30-
31-
import MakeTest<TaintTrackingTest>
3+
import TestUtilities.InlineFlowTest
4+
import DefaultFlowTest

go/ql/test/experimental/frameworks/Fiber/TaintTracking.go

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,4 @@
11
import go
2-
import TestUtilities.InlineExpectationsTest
32
import experimental.frameworks.Fiber
4-
5-
class Configuration extends TaintTracking::Configuration {
6-
Configuration() { this = "test-configuration" }
7-
8-
override predicate isSource(DataFlow::Node source) {
9-
exists(Function fn | fn.hasQualifiedName(_, "source") | source = fn.getACall().getResult())
10-
}
11-
12-
override predicate isSink(DataFlow::Node sink) {
13-
exists(Function fn | fn.hasQualifiedName(_, "sink") | sink = fn.getACall().getAnArgument())
14-
}
15-
}
16-
17-
module TaintTrackingTest implements TestSig {
18-
string getARelevantTag() { result = "taintSink" }
19-
20-
predicate hasActualResult(Location location, string element, string tag, string value) {
21-
tag = "taintSink" and
22-
exists(DataFlow::Node sink | any(Configuration c).hasFlow(_, sink) |
23-
element = sink.toString() and
24-
value = "" and
25-
sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
26-
location.getStartColumn(), location.getEndLine(), location.getEndColumn())
27-
)
28-
}
29-
}
30-
31-
import MakeTest<TaintTrackingTest>
3+
import TestUtilities.InlineFlowTest
4+
import DefaultFlowTest

go/ql/test/library-tests/semmle/go/dataflow/ListOfConstantsSanitizerGuards/test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ func main() {
138138
if switchStatementReturningTrueOnlyWhenConstant(s) {
139139
sink(s)
140140
} else {
141-
sink(s) // $ dataflow=s
141+
sink(s) // $ hasTaintFlow="s"
142142
}
143143
}
144144

145145
{
146146
s := source()
147147
if switchStatementReturningFalseOnlyWhenConstant("", s) {
148-
sink(s) // $ dataflow=s
148+
sink(s) // $ hasTaintFlow="s"
149149
} else {
150150
sink(s)
151151
}
@@ -157,7 +157,7 @@ func main() {
157157
if err != nil {
158158
sink(s)
159159
} else {
160-
sink(s) // $ dataflow=s
160+
sink(s) // $ hasTaintFlow="s"
161161
}
162162
}
163163

@@ -166,7 +166,7 @@ func main() {
166166
if switchStatementReturningNilOnlyWhenConstant(s) == nil {
167167
sink(s)
168168
} else {
169-
sink(s) // $ dataflow=s
169+
sink(s) // $ hasTaintFlow="s"
170170
}
171171
}
172172

@@ -175,25 +175,25 @@ func main() {
175175
if multipleSwitchStatementReturningTrueOnlyWhenConstant(s, getRandomString()) {
176176
sink(s)
177177
} else {
178-
sink(s) // $ dataflow=s
178+
sink(s) // $ hasTaintFlow="s"
179179
}
180180
}
181181

182182
{
183183
s := source()
184184
if switchStatementWithoutUsefulInfo(s) {
185-
sink(s) // $ dataflow=s
185+
sink(s) // $ hasTaintFlow="s"
186186
} else {
187-
sink(s) // $ dataflow=s
187+
sink(s) // $ hasTaintFlow="s"
188188
}
189189
}
190190

191191
{
192192
s := source()
193193
if switchStatementOverRandomString(s) {
194-
sink(s) // $ dataflow=s
194+
sink(s) // $ hasTaintFlow="s"
195195
} else {
196-
sink(s) // $ dataflow=s
196+
sink(s) // $ hasTaintFlow="s"
197197
}
198198
}
199199

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,3 @@
11
import go
2-
import TestUtilities.InlineExpectationsTest
3-
4-
class TestConfig extends TaintTracking::Configuration {
5-
TestConfig() { this = "test config" }
6-
7-
override predicate isSource(DataFlow::Node source) {
8-
source.(DataFlow::CallNode).getTarget().getName() = "source"
9-
}
10-
11-
override predicate isSink(DataFlow::Node sink) {
12-
sink = any(DataFlow::CallNode c | c.getTarget().getName() = "sink").getAnArgument()
13-
}
14-
}
15-
16-
module DataFlowTest implements TestSig {
17-
string getARelevantTag() { result = "dataflow" }
18-
19-
predicate hasActualResult(Location location, string element, string tag, string value) {
20-
tag = "dataflow" and
21-
exists(DataFlow::Node sink | any(TestConfig c).hasFlow(_, sink) |
22-
element = sink.toString() and
23-
value = sink.toString() and
24-
sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
25-
location.getStartColumn(), location.getEndLine(), location.getEndColumn())
26-
)
27-
}
28-
}
29-
30-
import MakeTest<DataFlowTest>
2+
import TestUtilities.InlineFlowTest
3+
import TaintFlowTest<DefaultFlowConfig>
Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,20 @@
11
import go
2-
import TestUtilities.InlineExpectationsTest
2+
import TestUtilities.InlineFlowTest
33

4-
class Configuration extends TaintTracking::Configuration {
5-
Configuration() { this = "test-configuration" }
6-
7-
override predicate isSource(DataFlow::Node source) {
8-
source =
9-
any(DataFlow::CallNode c | c.getCalleeName() in ["getTaintedByteArray", "getTaintedPatch"])
10-
.getResult(0)
4+
module Config implements DataFlow::ConfigSig {
5+
predicate isSource(DataFlow::Node source) {
6+
exists(Function fn | fn.hasQualifiedName(_, ["getTaintedByteArray", "getTaintedPatch"]) |
7+
source = fn.getACall().getResult()
8+
)
119
}
1210

13-
override predicate isSink(DataFlow::Node sink) {
14-
sink =
15-
any(DataFlow::CallNode c | c.getCalleeName() in ["sinkByteArray", "sinkPatch"]).getArgument(0)
16-
}
17-
}
18-
19-
module TaintFlowTest implements TestSig {
20-
string getARelevantTag() { result = "taintflow" }
21-
22-
predicate hasActualResult(Location location, string element, string tag, string value) {
23-
tag = "taintflow" and
24-
exists(DataFlow::Node sink | any(Configuration c).hasFlow(_, sink) |
25-
element = sink.toString() and
26-
value = "" and
27-
sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
28-
location.getStartColumn(), location.getEndLine(), location.getEndColumn())
11+
predicate isSink(DataFlow::Node sink) {
12+
exists(Function fn | fn.hasQualifiedName(_, ["sinkByteArray", "sinkPatch"]) |
13+
sink = fn.getACall().getAnArgument()
2914
)
3015
}
16+
17+
int fieldFlowBranchLimit() { result = 1000 }
3118
}
3219

33-
import MakeTest<TaintFlowTest>
20+
import TaintFlowTest<Config>

0 commit comments

Comments
 (0)