Skip to content

Commit 9731989

Browse files
committed
Swift: add tests for flow through constructors
1 parent f3f5f6e commit 9731989

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

swift/ql/test/library-tests/dataflow/dataflow/DataFlow.expected

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ edges
155155
| test.swift:472:20:472:20 | cx [x] : | test.swift:472:20:472:23 | .x : |
156156
| test.swift:472:20:472:23 | .x : | test.swift:473:15:473:15 | z1 |
157157
| test.swift:479:14:479:21 | call to source() : | test.swift:479:13:479:21 | call to +(_:) |
158+
| test.swift:489:10:489:13 | s : | test.swift:490:13:490:13 | s : |
159+
| test.swift:490:7:490:7 | [post] self [str] : | test.swift:489:5:491:5 | self[return] [str] : |
160+
| test.swift:490:13:490:13 | s : | test.swift:490:7:490:7 | [post] self [str] : |
161+
| test.swift:496:7:496:7 | [post] self [str] : | test.swift:497:17:497:17 | self [str] : |
162+
| test.swift:496:20:496:28 | call to source3() : | test.swift:489:10:489:13 | s : |
163+
| test.swift:496:20:496:28 | call to source3() : | test.swift:496:7:496:7 | [post] self [str] : |
164+
| test.swift:497:17:497:17 | self [str] : | test.swift:497:17:497:17 | .str |
158165
nodes
159166
| file://:0:0:0:0 | .a [x] : | semmle.label | .a [x] : |
160167
| file://:0:0:0:0 | .x : | semmle.label | .x : |
@@ -328,6 +335,14 @@ nodes
328335
| test.swift:479:13:479:21 | call to +(_:) | semmle.label | call to +(_:) |
329336
| test.swift:479:14:479:21 | call to source() : | semmle.label | call to source() : |
330337
| test.swift:480:14:480:21 | call to source() | semmle.label | call to source() |
338+
| test.swift:489:5:491:5 | self[return] [str] : | semmle.label | self[return] [str] : |
339+
| test.swift:489:10:489:13 | s : | semmle.label | s : |
340+
| test.swift:490:7:490:7 | [post] self [str] : | semmle.label | [post] self [str] : |
341+
| test.swift:490:13:490:13 | s : | semmle.label | s : |
342+
| test.swift:496:7:496:7 | [post] self [str] : | semmle.label | [post] self [str] : |
343+
| test.swift:496:20:496:28 | call to source3() : | semmle.label | call to source3() : |
344+
| test.swift:497:17:497:17 | .str | semmle.label | .str |
345+
| test.swift:497:17:497:17 | self [str] : | semmle.label | self [str] : |
331346
subpaths
332347
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | arg1 : | test.swift:65:1:70:1 | arg2[return] : | test.swift:75:31:75:32 | [post] &... : |
333348
| test.swift:114:19:114:19 | arg : | test.swift:109:9:109:14 | arg : | test.swift:110:12:110:12 | arg : | test.swift:114:12:114:22 | call to ... : |
@@ -360,6 +375,8 @@ subpaths
360375
| test.swift:303:15:303:16 | ...! : | file://:0:0:0:0 | [summary param] this in signum() : | file://:0:0:0:0 | [summary] to write: return (return) in signum() : | test.swift:303:15:303:25 | call to signum() |
361376
| test.swift:468:12:468:12 | x : | test.swift:462:9:462:9 | value : | file://:0:0:0:0 | [post] self [x] : | test.swift:468:5:468:5 | [post] cx [x] : |
362377
| test.swift:472:20:472:20 | cx [x] : | test.swift:462:9:462:9 | self [x] : | file://:0:0:0:0 | .x : | test.swift:472:20:472:23 | .x : |
378+
| test.swift:496:20:496:28 | call to source3() : | test.swift:489:10:489:13 | s : | test.swift:489:5:491:5 | self[return] [str] : | test.swift:496:7:496:7 | [post] self [str] : |
379+
| test.swift:496:20:496:28 | call to source3() : | test.swift:489:10:489:13 | s : | test.swift:490:7:490:7 | [post] self [str] : | test.swift:496:7:496:7 | [post] self [str] : |
363380
#select
364381
| test.swift:7:15:7:15 | t1 | test.swift:6:19:6:26 | call to source() : | test.swift:7:15:7:15 | t1 | result |
365382
| test.swift:9:15:9:15 | t1 | test.swift:6:19:6:26 | call to source() : | test.swift:9:15:9:15 | t1 | result |
@@ -414,3 +431,4 @@ subpaths
414431
| test.swift:473:15:473:15 | z1 | test.swift:259:12:259:19 | call to source() : | test.swift:473:15:473:15 | z1 | result |
415432
| test.swift:479:13:479:21 | call to +(_:) | test.swift:479:14:479:21 | call to source() : | test.swift:479:13:479:21 | call to +(_:) | result |
416433
| test.swift:480:14:480:21 | call to source() | test.swift:480:14:480:21 | call to source() | test.swift:480:14:480:21 | call to source() | result |
434+
| test.swift:497:17:497:17 | .str | test.swift:496:20:496:28 | call to source3() : | test.swift:497:17:497:17 | .str | result |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.swift:497:17:497:17 | .str | Unexpected result: flow=496 |

swift/ql/test/library-tests/dataflow/dataflow/FlowConfig.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TestConfiguration extends DataFlow::Configuration {
1515

1616
override predicate isSink(DataFlow::Node sink) {
1717
exists(CallExpr sinkCall |
18-
sinkCall.getStaticTarget().getName() = ["sink(arg:)", "sink(opt:)"] and
18+
sinkCall.getStaticTarget().getName() = ["sink(arg:)", "sink(opt:)", "sink(str:)"] and
1919
sinkCall.getAnArgument().getExpr() = sink.asExpr()
2020
)
2121
}

swift/ql/test/library-tests/dataflow/dataflow/LocalFlow.expected

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,3 +391,23 @@
391391
| test.swift:474:11:474:15 | SSA def(z2) | test.swift:475:15:475:15 | z2 |
392392
| test.swift:474:20:474:23 | .x | test.swift:474:11:474:15 | SSA def(z2) |
393393
| test.swift:479:14:479:21 | call to source() | test.swift:479:13:479:21 | call to +(_:) |
394+
| test.swift:487:7:487:7 | SSA def(self) | test.swift:487:7:487:7 | self[return] |
395+
| test.swift:487:7:487:7 | self | test.swift:487:7:487:7 | SSA def(self) |
396+
| test.swift:488:9:488:9 | self | test.swift:488:9:488:9 | SSA def(self) |
397+
| test.swift:488:9:488:9 | self | test.swift:488:9:488:9 | SSA def(self) |
398+
| test.swift:488:9:488:9 | self | test.swift:488:9:488:9 | SSA def(self) |
399+
| test.swift:488:9:488:9 | value | test.swift:488:9:488:9 | SSA def(value) |
400+
| test.swift:489:5:489:5 | SSA def(self) | test.swift:490:7:490:7 | self |
401+
| test.swift:489:5:489:5 | self | test.swift:489:5:489:5 | SSA def(self) |
402+
| test.swift:489:10:489:13 | SSA def(s) | test.swift:490:13:490:13 | s |
403+
| test.swift:489:10:489:13 | s | test.swift:489:10:489:13 | SSA def(s) |
404+
| test.swift:490:7:490:7 | [post] self | test.swift:489:5:491:5 | self[return] |
405+
| test.swift:490:7:490:7 | self | test.swift:489:5:491:5 | self[return] |
406+
| test.swift:495:17:495:17 | SSA def(self) | test.swift:496:7:496:7 | self |
407+
| test.swift:495:17:495:17 | self | test.swift:495:17:495:17 | SSA def(self) |
408+
| test.swift:496:7:496:7 | [post] self | test.swift:497:17:497:17 | self |
409+
| test.swift:496:7:496:7 | self | test.swift:497:17:497:17 | self |
410+
| test.swift:497:17:497:17 | [post] self | test.swift:495:17:498:5 | self[return] |
411+
| test.swift:497:17:497:17 | self | test.swift:495:17:498:5 | self[return] |
412+
| test.swift:501:21:501:27 | SSA def(path) | test.swift:503:37:503:37 | path |
413+
| test.swift:501:21:501:27 | path | test.swift:501:21:501:27 | SSA def(path) |

swift/ql/test/library-tests/dataflow/dataflow/test.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,26 @@ func testIdentityArithmetic() {
479479
sink(arg: +source()) // $ flow=479
480480
sink(arg: (source())) // $ flow=480
481481
}
482+
483+
func sink(str: String) {}
484+
485+
func source3() -> String { return "" }
486+
487+
class MyClass {
488+
var str: String
489+
init(s: String) {
490+
str = s
491+
}
492+
}
493+
494+
extension MyClass {
495+
convenience init(contentsOfFile: String) {
496+
self.init(s: source3()) // taint should flow from the source String(contentsOfFile:) into MyClass
497+
sink(str: str)
498+
}
499+
}
500+
501+
func extensionInits(path: String) {
502+
sink(str: MyClass(s: source3()).str)
503+
sink(str: MyClass(contentsOfFile: path).str)
504+
}

0 commit comments

Comments
 (0)