Skip to content

Commit c2ee5fe

Browse files
committed
Swift: Add inlineExpectations test.
1 parent 56fddd7 commit c2ee5fe

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
| string.swift:7:13:7:13 | "..." | Unexpected result: taintedFromLine=5 |
2+
| string.swift:9:13:9:13 | "..." | Unexpected result: taintedFromLine=5 |
3+
| string.swift:11:13:11:13 | "..." | Unexpected result: taintedFromLine=5 |
4+
| string.swift:16:13:16:13 | "..." | Unexpected result: taintedFromLine=5 |
5+
| string.swift:18:13:18:13 | "..." | Unexpected result: taintedFromLine=5 |
6+
| string.swift:31:13:31:13 | tainted | Unexpected result: taintedFromLine=28 |
7+
| string.swift:34:13:34:21 | ... call to +(_:_:) ... | Unexpected result: taintedFromLine=28 |
8+
| string.swift:35:13:35:23 | ... call to +(_:_:) ... | Unexpected result: taintedFromLine=28 |
9+
| string.swift:36:13:36:23 | ... call to +(_:_:) ... | Unexpected result: taintedFromLine=28 |
10+
| string.swift:39:13:39:29 | ... call to +(_:_:) ... | Unexpected result: taintedFromLine=28 |
11+
| try.swift:9:13:9:24 | try ... | Unexpected result: taintedFromLine=9 |
12+
| try.swift:15:12:15:24 | try! ... | Unexpected result: taintedFromLine=15 |
13+
| try.swift:18:12:18:27 | ...! | Unexpected result: taintedFromLine=18 |
14+
| url.swift:18:12:18:12 | urlTainted | Unexpected result: taintedFromLine=13 |
15+
| url.swift:21:12:21:49 | ...! | Unexpected result: taintedFromLine=13 |
16+
| url.swift:23:12:23:54 | ...! | Unexpected result: taintedFromLine=13 |
17+
| url.swift:39:12:39:12 | ...! | Unexpected result: taintedFromLine=13 |
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @kind path-problem
3+
*/
4+
5+
import swift
6+
import codeql.swift.dataflow.TaintTracking
7+
import codeql.swift.dataflow.DataFlow::DataFlow
8+
import TestUtilities.InlineExpectationsTest
9+
10+
class TestConfiguration extends TaintTracking::Configuration {
11+
TestConfiguration() { this = "TestConfiguration" }
12+
13+
override predicate isSource(Node src) {
14+
src.asExpr().(CallExpr).getStaticTarget().getName().matches("source%")
15+
}
16+
17+
override predicate isSink(Node sink) {
18+
exists(CallExpr sinkCall |
19+
sinkCall.getStaticTarget().getName().matches("sink%") and
20+
sinkCall.getAnArgument().getExpr() = sink.asExpr()
21+
)
22+
}
23+
24+
override int explorationLimit() { result = 100 }
25+
}
26+
27+
class TaintTest extends InlineExpectationsTest {
28+
TaintTest() { this = "taintedFromLine" }
29+
30+
override string getARelevantTag() { result = "taintedFromLine" }
31+
32+
override predicate hasActualResult(Location location, string element, string tag, string value) {
33+
exists(TestConfiguration config, Node source, Node sink, Expr sinkExpr |
34+
config.hasFlow(source, sink) and
35+
sinkExpr = sink.asExpr() and
36+
location = sinkExpr.getLocation() and
37+
element = sinkExpr.toString() and
38+
tag = "taintedFromLine" and
39+
value = source.asExpr().getLocation().getStartLine().toString()
40+
)
41+
}
42+
}

0 commit comments

Comments
 (0)