Skip to content

Commit 9f2abf3

Browse files
authored
Swift: more inout dataflow tests
1 parent 97815bf commit 9f2abf3

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ edges
2222
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | WriteDef : |
2323
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | arg1 : |
2424
| test.swift:75:21:75:22 | &... : | test.swift:75:5:75:33 | arg2 : |
25+
| test.swift:86:15:86:22 | call to source : | test.swift:87:9:87:9 | arg[return] : |
26+
| test.swift:87:9:87:9 | arg[return] : | test.swift:104:9:104:54 | arg : |
27+
| test.swift:104:9:104:54 | arg : | test.swift:105:19:105:19 | x |
2528
nodes
2629
| test.swift:6:19:6:26 | call to source : | semmle.label | call to source : |
2730
| test.swift:7:15:7:15 | t1 | semmle.label | t1 |
@@ -56,6 +59,10 @@ nodes
5659
| test.swift:75:5:75:33 | arg2 : | semmle.label | arg2 : |
5760
| test.swift:75:21:75:22 | &... : | semmle.label | &... : |
5861
| test.swift:77:15:77:15 | y | semmle.label | y |
62+
| test.swift:86:15:86:22 | call to source : | semmle.label | call to source : |
63+
| test.swift:87:9:87:9 | arg[return] : | semmle.label | arg[return] : |
64+
| test.swift:104:9:104:54 | arg : | semmle.label | arg : |
65+
| test.swift:105:19:105:19 | x | semmle.label | x |
5966
subpaths
6067
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | WriteDef : | test.swift:69:5:69:5 | arg2[return] : | test.swift:75:5:75:33 | arg2 : |
6168
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | arg1 : | test.swift:69:5:69:5 | arg2[return] : | test.swift:75:5:75:33 | arg2 : |
@@ -69,3 +76,4 @@ subpaths
6976
| test.swift:50:15:50:15 | t | test.swift:43:19:43:26 | call to source : | test.swift:50:15:50:15 | t | result |
7077
| test.swift:62:15:62:15 | x | test.swift:54:11:54:18 | call to source : | test.swift:62:15:62:15 | x | result |
7178
| test.swift:77:15:77:15 | y | test.swift:73:18:73:25 | call to source : | test.swift:77:15:77:15 | y | result |
79+
| test.swift:105:19:105:19 | x | test.swift:86:15:86:22 | call to source : | test.swift:105:19:105:19 | x | result |

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,21 @@
5151
| test.swift:75:5:75:33 | arg2 | test.swift:75:5:75:33 | WriteDef |
5252
| test.swift:75:22:75:22 | x | test.swift:75:21:75:22 | &... |
5353
| test.swift:75:32:75:32 | y | test.swift:75:31:75:32 | &... |
54+
| test.swift:84:48:84:54 | WriteDef | test.swift:85:8:85:8 | bool |
55+
| test.swift:84:48:84:54 | bool | test.swift:85:8:85:8 | bool |
56+
| test.swift:86:9:86:22 | WriteDef | test.swift:87:9:87:9 | arg[return] |
57+
| test.swift:86:15:86:22 | call to source | test.swift:86:9:86:22 | WriteDef |
58+
| test.swift:93:17:93:23 | WriteDef | test.swift:104:50:104:50 | bool |
59+
| test.swift:93:17:93:23 | bool | test.swift:104:50:104:50 | bool |
60+
| test.swift:95:13:95:16 | WriteDef | test.swift:96:19:96:19 | x |
61+
| test.swift:95:22:95:22 | 0 | test.swift:95:13:95:16 | WriteDef |
62+
| test.swift:96:19:96:19 | x | test.swift:97:40:97:40 | x |
63+
| test.swift:97:9:97:41 | WriteDef | test.swift:98:19:98:19 | x |
64+
| test.swift:97:9:97:41 | arg | test.swift:97:9:97:41 | WriteDef |
65+
| test.swift:97:40:97:40 | x | test.swift:97:39:97:40 | &... |
66+
| test.swift:102:13:102:16 | WriteDef | test.swift:103:19:103:19 | x |
67+
| test.swift:102:22:102:22 | 0 | test.swift:102:13:102:16 | WriteDef |
68+
| test.swift:103:19:103:19 | x | test.swift:104:41:104:41 | x |
69+
| test.swift:104:9:104:54 | WriteDef | test.swift:105:19:105:19 | x |
70+
| test.swift:104:9:104:54 | arg | test.swift:104:9:104:54 | WriteDef |
71+
| test.swift:104:41:104:41 | x | test.swift:104:40:104:41 | &... |

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,33 @@ func swapUser() {
7575
inoutSwap(arg1: &x, arg2: &y)
7676
sink(arg: x)
7777
sink(arg: y)
78-
}
78+
}
79+
80+
func inoutSourceWithoutReturn(arg: inout Int) {
81+
arg = source()
82+
}
83+
84+
func inoutSourceMultipleReturn(arg: inout Int, bool: Bool) {
85+
if(bool) {
86+
arg = source()
87+
return
88+
} else {
89+
arg = source()
90+
}
91+
}
92+
93+
func inoutUser2(bool: Bool) {
94+
do {
95+
var x: Int = 0
96+
sink(arg: x) // clean
97+
inoutSourceWithoutReturn(arg: &x)
98+
sink(arg: x) // tainted
99+
}
100+
101+
do {
102+
var x: Int = 0
103+
sink(arg: x) // clean
104+
inoutSourceMultipleReturn(arg: &x, bool: bool)
105+
sink(arg: x) // tainted by two sources
106+
}
107+
}

0 commit comments

Comments
 (0)