Skip to content

Commit 1d43abf

Browse files
committed
Swift: Model Collection.makeIterator().
1 parent d1915c7 commit 1d43abf

File tree

6 files changed

+49
-6
lines changed

6 files changed

+49
-6
lines changed

swift/ql/lib/codeql/swift/frameworks/StandardLibrary/Collection.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ private class CollectionSummaries extends SummaryModelCsv {
4444
";Collection;true;trimmingPrefix(_:);;;Argument[-1].CollectionElement;ReturnValue.CollectionElement;value",
4545
";Collection;true;trimmingPrefix(while:);;;Argument[-1];ReturnValue;taint",
4646
";Collection;true;trimmingPrefix(while:);;;Argument[-1].CollectionElement;ReturnValue.CollectionElement;value",
47+
";Collection;true;makeIterator();;;Argument[-1].CollectionElement;ReturnValue.CollectionElement;value",
4748
";RangeReplaceableCollection;true;init(_:);;;Argument[0];ReturnValue.CollectionElement;taint",
4849
";RangeReplaceableCollection;true;init(_:);;;Argument[0].CollectionElement;ReturnValue.CollectionElement;value",
4950
";RangeReplaceableCollection;true;init(repeating:count:);;;Argument[0];ReturnValue.CollectionElement;value",

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,15 @@ edges
135135
| test2.swift:69:10:69:10 | key | test2.swift:70:19:70:19 | key | provenance | |
136136
| test2.swift:69:25:69:25 | call to makeIterator() [Collection element, Tuple element at index 0] | test2.swift:69:5:69:5 | $generator [Collection element, Tuple element at index 0] | provenance | |
137137
| test2.swift:69:25:69:25 | d4 [Collection element, Tuple element at index 0] | test2.swift:69:25:69:25 | call to makeIterator() [Collection element, Tuple element at index 0] | provenance | |
138+
| test2.swift:76:14:76:47 | [...] [Collection element] | test2.swift:78:14:78:14 | a1 [Collection element] | provenance | |
138139
| test2.swift:76:14:76:47 | [...] [Collection element] | test2.swift:82:19:82:19 | a1 [Collection element] | provenance | |
139140
| test2.swift:76:14:76:47 | [...] [Collection element] | test2.swift:84:20:84:20 | a1 [Collection element] | provenance | |
140141
| test2.swift:76:30:76:46 | call to source(_:) | test2.swift:76:14:76:47 | [...] [Collection element] | provenance | |
142+
| test2.swift:78:5:78:5 | $v$generator [Collection element] | test2.swift:78:5:78:5 | call to next() [some:0] | provenance | |
143+
| test2.swift:78:5:78:5 | call to next() [some:0] | test2.swift:78:9:78:9 | v | provenance | |
144+
| test2.swift:78:9:78:9 | v | test2.swift:79:19:79:19 | v | provenance | |
145+
| test2.swift:78:14:78:14 | a1 [Collection element] | test2.swift:78:14:78:14 | call to makeIterator() [Collection element] | provenance | |
146+
| test2.swift:78:14:78:14 | call to makeIterator() [Collection element] | test2.swift:78:5:78:5 | $v$generator [Collection element] | provenance | |
141147
| test2.swift:82:19:82:19 | a1 [Collection element] | test2.swift:82:19:82:24 | ...[...] | provenance | |
142148
| test2.swift:84:5:84:5 | $generator [Collection element, Tuple element at index 1] | test2.swift:84:5:84:5 | call to next() [some:0, Tuple element at index 1] | provenance | |
143149
| test2.swift:84:5:84:5 | call to next() [some:0, Tuple element at index 1] | test2.swift:84:9:84:15 | (...) [Tuple element at index 1] | provenance | |
@@ -146,9 +152,15 @@ edges
146152
| test2.swift:84:20:84:20 | a1 [Collection element] | test2.swift:84:20:84:34 | call to enumerated() [Collection element, Tuple element at index 1] | provenance | |
147153
| test2.swift:84:20:84:34 | call to enumerated() [Collection element, Tuple element at index 1] | test2.swift:84:20:84:34 | call to makeIterator() [Collection element, Tuple element at index 1] | provenance | |
148154
| test2.swift:84:20:84:34 | call to makeIterator() [Collection element, Tuple element at index 1] | test2.swift:84:5:84:5 | $generator [Collection element, Tuple element at index 1] | provenance | |
155+
| test2.swift:93:5:93:5 | [post] a2 [Collection element] | test2.swift:95:14:95:14 | a2 [Collection element] | provenance | |
149156
| test2.swift:93:5:93:5 | [post] a2 [Collection element] | test2.swift:99:19:99:19 | a2 [Collection element] | provenance | |
150157
| test2.swift:93:5:93:5 | [post] a2 [Collection element] | test2.swift:101:20:101:20 | a2 [Collection element] | provenance | |
151158
| test2.swift:93:13:93:29 | call to source(_:) | test2.swift:93:5:93:5 | [post] a2 [Collection element] | provenance | |
159+
| test2.swift:95:5:95:5 | $v$generator [Collection element] | test2.swift:95:5:95:5 | call to next() [some:0] | provenance | |
160+
| test2.swift:95:5:95:5 | call to next() [some:0] | test2.swift:95:9:95:9 | v | provenance | |
161+
| test2.swift:95:9:95:9 | v | test2.swift:96:19:96:19 | v | provenance | |
162+
| test2.swift:95:14:95:14 | a2 [Collection element] | test2.swift:95:14:95:14 | call to makeIterator() [Collection element] | provenance | |
163+
| test2.swift:95:14:95:14 | call to makeIterator() [Collection element] | test2.swift:95:5:95:5 | $v$generator [Collection element] | provenance | |
152164
| test2.swift:99:19:99:19 | a2 [Collection element] | test2.swift:99:19:99:24 | ...[...] | provenance | |
153165
| test2.swift:101:5:101:5 | $generator [Collection element, Tuple element at index 1] | test2.swift:101:5:101:5 | call to next() [some:0, Tuple element at index 1] | provenance | |
154166
| test2.swift:101:5:101:5 | call to next() [some:0, Tuple element at index 1] | test2.swift:101:9:101:15 | (...) [Tuple element at index 1] | provenance | |
@@ -712,9 +724,15 @@ edges
712724
| test.swift:849:19:849:24 | v | test.swift:850:15:850:15 | v | provenance | |
713725
| test.swift:856:29:856:40 | args [Collection element] | test.swift:859:15:859:15 | args [Collection element] | provenance | |
714726
| test.swift:856:29:856:40 | args [Collection element] | test.swift:860:15:860:15 | args [Collection element] | provenance | |
727+
| test.swift:856:29:856:40 | args [Collection element] | test.swift:862:16:862:16 | args [Collection element] | provenance | |
715728
| test.swift:856:29:856:40 | args [Collection element] | test.swift:867:15:867:15 | args [Collection element] | provenance | |
716729
| test.swift:859:15:859:15 | args [Collection element] | test.swift:859:15:859:21 | ...[...] | provenance | |
717730
| test.swift:860:15:860:15 | args [Collection element] | test.swift:860:15:860:21 | ...[...] | provenance | |
731+
| test.swift:862:5:862:5 | $arg$generator [Collection element] | test.swift:862:5:862:5 | call to next() [some:0] | provenance | |
732+
| test.swift:862:5:862:5 | call to next() [some:0] | test.swift:862:9:862:9 | arg | provenance | |
733+
| test.swift:862:9:862:9 | arg | test.swift:863:19:863:19 | arg | provenance | |
734+
| test.swift:862:16:862:16 | args [Collection element] | test.swift:862:16:862:16 | call to makeIterator() [Collection element] | provenance | |
735+
| test.swift:862:16:862:16 | call to makeIterator() [Collection element] | test.swift:862:5:862:5 | $arg$generator [Collection element] | provenance | |
718736
| test.swift:866:21:866:29 | enter #keyPath(...) [Collection element] | test.swift:866:27:866:29 | KeyPathComponent | provenance | |
719737
| test.swift:866:27:866:29 | KeyPathComponent | test.swift:866:21:866:29 | exit #keyPath(...) | provenance | |
720738
| test.swift:867:15:867:15 | args [Collection element] | test.swift:866:21:866:29 | enter #keyPath(...) [Collection element] | provenance | |
@@ -908,6 +926,12 @@ nodes
908926
| test2.swift:70:19:70:19 | key | semmle.label | key |
909927
| test2.swift:76:14:76:47 | [...] [Collection element] | semmle.label | [...] [Collection element] |
910928
| test2.swift:76:30:76:46 | call to source(_:) | semmle.label | call to source(_:) |
929+
| test2.swift:78:5:78:5 | $v$generator [Collection element] | semmle.label | $v$generator [Collection element] |
930+
| test2.swift:78:5:78:5 | call to next() [some:0] | semmle.label | call to next() [some:0] |
931+
| test2.swift:78:9:78:9 | v | semmle.label | v |
932+
| test2.swift:78:14:78:14 | a1 [Collection element] | semmle.label | a1 [Collection element] |
933+
| test2.swift:78:14:78:14 | call to makeIterator() [Collection element] | semmle.label | call to makeIterator() [Collection element] |
934+
| test2.swift:79:19:79:19 | v | semmle.label | v |
911935
| test2.swift:82:19:82:19 | a1 [Collection element] | semmle.label | a1 [Collection element] |
912936
| test2.swift:82:19:82:24 | ...[...] | semmle.label | ...[...] |
913937
| test2.swift:84:5:84:5 | $generator [Collection element, Tuple element at index 1] | semmle.label | $generator [Collection element, Tuple element at index 1] |
@@ -920,6 +944,12 @@ nodes
920944
| test2.swift:86:19:86:19 | v | semmle.label | v |
921945
| test2.swift:93:5:93:5 | [post] a2 [Collection element] | semmle.label | [post] a2 [Collection element] |
922946
| test2.swift:93:13:93:29 | call to source(_:) | semmle.label | call to source(_:) |
947+
| test2.swift:95:5:95:5 | $v$generator [Collection element] | semmle.label | $v$generator [Collection element] |
948+
| test2.swift:95:5:95:5 | call to next() [some:0] | semmle.label | call to next() [some:0] |
949+
| test2.swift:95:9:95:9 | v | semmle.label | v |
950+
| test2.swift:95:14:95:14 | a2 [Collection element] | semmle.label | a2 [Collection element] |
951+
| test2.swift:95:14:95:14 | call to makeIterator() [Collection element] | semmle.label | call to makeIterator() [Collection element] |
952+
| test2.swift:96:19:96:19 | v | semmle.label | v |
923953
| test2.swift:99:19:99:19 | a2 [Collection element] | semmle.label | a2 [Collection element] |
924954
| test2.swift:99:19:99:24 | ...[...] | semmle.label | ...[...] |
925955
| test2.swift:101:5:101:5 | $generator [Collection element, Tuple element at index 1] | semmle.label | $generator [Collection element, Tuple element at index 1] |
@@ -1518,6 +1548,12 @@ nodes
15181548
| test.swift:859:15:859:21 | ...[...] | semmle.label | ...[...] |
15191549
| test.swift:860:15:860:15 | args [Collection element] | semmle.label | args [Collection element] |
15201550
| test.swift:860:15:860:21 | ...[...] | semmle.label | ...[...] |
1551+
| test.swift:862:5:862:5 | $arg$generator [Collection element] | semmle.label | $arg$generator [Collection element] |
1552+
| test.swift:862:5:862:5 | call to next() [some:0] | semmle.label | call to next() [some:0] |
1553+
| test.swift:862:9:862:9 | arg | semmle.label | arg |
1554+
| test.swift:862:16:862:16 | args [Collection element] | semmle.label | args [Collection element] |
1555+
| test.swift:862:16:862:16 | call to makeIterator() [Collection element] | semmle.label | call to makeIterator() [Collection element] |
1556+
| test.swift:863:19:863:19 | arg | semmle.label | arg |
15211557
| test.swift:866:21:866:29 | enter #keyPath(...) [Collection element] | semmle.label | enter #keyPath(...) [Collection element] |
15221558
| test.swift:866:21:866:29 | exit #keyPath(...) | semmle.label | exit #keyPath(...) |
15231559
| test.swift:866:27:866:29 | KeyPathComponent | semmle.label | KeyPathComponent |
@@ -1661,8 +1697,10 @@ subpaths
16611697
| test2.swift:53:15:53:28 | ... ??(_:_:) ... | test2.swift:46:17:46:33 | call to source(_:) | test2.swift:53:15:53:28 | ... ??(_:_:) ... | result |
16621698
| test2.swift:54:15:54:24 | ...! | test2.swift:46:17:46:33 | call to source(_:) | test2.swift:54:15:54:24 | ...! | result |
16631699
| test2.swift:70:19:70:19 | key | test2.swift:60:8:60:24 | call to source(_:) | test2.swift:70:19:70:19 | key | result |
1700+
| test2.swift:79:19:79:19 | v | test2.swift:76:30:76:46 | call to source(_:) | test2.swift:79:19:79:19 | v | result |
16641701
| test2.swift:82:19:82:24 | ...[...] | test2.swift:76:30:76:46 | call to source(_:) | test2.swift:82:19:82:24 | ...[...] | result |
16651702
| test2.swift:86:19:86:19 | v | test2.swift:76:30:76:46 | call to source(_:) | test2.swift:86:19:86:19 | v | result |
1703+
| test2.swift:96:19:96:19 | v | test2.swift:93:13:93:29 | call to source(_:) | test2.swift:96:19:96:19 | v | result |
16661704
| test2.swift:99:19:99:24 | ...[...] | test2.swift:93:13:93:29 | call to source(_:) | test2.swift:99:19:99:24 | ...[...] | result |
16671705
| test2.swift:103:19:103:19 | v | test2.swift:93:13:93:29 | call to source(_:) | test2.swift:103:19:103:19 | v | result |
16681706
| test.swift:7:15:7:15 | t1 | test.swift:6:19:6:26 | call to source() | test.swift:7:15:7:15 | t1 | result |
@@ -1789,6 +1827,7 @@ subpaths
17891827
| test.swift:850:15:850:15 | v | test.swift:872:18:872:25 | call to source() | test.swift:850:15:850:15 | v | result |
17901828
| test.swift:859:15:859:21 | ...[...] | test.swift:873:24:873:31 | call to source() | test.swift:859:15:859:21 | ...[...] | result |
17911829
| test.swift:860:15:860:21 | ...[...] | test.swift:873:24:873:31 | call to source() | test.swift:860:15:860:21 | ...[...] | result |
1830+
| test.swift:863:19:863:19 | arg | test.swift:873:24:873:31 | call to source() | test.swift:863:19:863:19 | arg | result |
17921831
| test.swift:867:15:867:38 | \\...[...] | test.swift:873:24:873:31 | call to source() | test.swift:867:15:867:38 | \\...[...] | result |
17931832
| test.swift:880:19:880:19 | elem | test.swift:877:21:877:28 | call to source() | test.swift:880:19:880:19 | elem | result |
17941833
| test.swift:884:15:884:31 | ...! | test.swift:877:21:877:28 | call to source() | test.swift:884:15:884:31 | ...! | result |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ func testVarargs3(_ v: Int, _ args: Int...) {
860860
sink(arg: args[1]) // $ flow=873
861861

862862
for arg in args {
863-
sink(arg: arg) // $ MISSING: flow=873
863+
sink(arg: arg) // $ flow=873
864864
}
865865

866866
let myKeyPath = \[Int][1]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func testArrays1() {
7676
var a1 = ["a", "b", "c", source("source5")]
7777

7878
for v in a1 {
79-
sink(arg: v) // $ MISSING: flow=source5
79+
sink(arg: v) // $ flow=source5
8080
}
8181
for ix in 0 ..< a1.count {
8282
sink(arg: a1[ix]) // $ flow=source5
@@ -93,7 +93,7 @@ func testArrays2() {
9393
a2[1] = source("source6")
9494

9595
for v in a2 {
96-
sink(arg: v) // $ MISSING: flow=source6
96+
sink(arg: v) // $ flow=source6
9797
}
9898
for ix in 0 ..< a2.count {
9999
sink(arg: a2[ix]) // $ flow=source6

swift/ql/test/query-tests/Security/CWE-020/MissingRegexAnchor.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
| UnanchoredUrlRegex.swift:71:46:71:46 | https?://good.com | When this is used as a regular expression on a URL, it may match anywhere, and arbitrary hosts may come before or after it. |
4747
| UnanchoredUrlRegex.swift:78:39:78:39 | https?://good.com | When this is used as a regular expression on a URL, it may match anywhere, and arbitrary hosts may come before or after it. |
4848
| UnanchoredUrlRegex.swift:79:39:79:39 | https?://good.com:8080 | When this is used as a regular expression on a URL, it may match anywhere, and arbitrary hosts may come before or after it. |
49+
| UnanchoredUrlRegex.swift:82:3:82:3 | https?://good.com | When this is used as a regular expression on a URL, it may match anywhere, and arbitrary hosts may come before or after it. |
50+
| UnanchoredUrlRegex.swift:83:3:83:3 | https?:\\/\\/good.com | When this is used as a regular expression on a URL, it may match anywhere, and arbitrary hosts may come before or after it. |
51+
| UnanchoredUrlRegex.swift:84:3:84:3 | ^https?://good.com | This hostname pattern may match any domain name, as it is missing a '$' or '/' at the end. |
4952
| UnanchoredUrlRegex.swift:91:3:91:3 | https?://good.com | When this is used as a regular expression on a URL, it may match anywhere, and arbitrary hosts may come before or after it. |
5053
| UnanchoredUrlRegex.swift:101:39:101:39 | https?:\\/\\/good.com\\/([0-9]+) | When this is used as a regular expression on a URL, it may match anywhere, and arbitrary hosts may come before or after it. |
5154
| UnanchoredUrlRegex.swift:107:39:107:39 | example\\.com\|whatever | When this is used as a regular expression on a URL, it may match anywhere, and arbitrary hosts may come before or after it. |

swift/ql/test/query-tests/Security/CWE-020/UnanchoredUrlRegex.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ func tests(url: String, secure: Bool) throws {
7979
_ = try NSRegularExpression(pattern: #"https?://good.com:8080"#).firstMatch(in: input, range: inputRange) // BAD (missing anchor)
8080

8181
let trustedUrlRegexs = [
82-
"https?://good.com", // BAD (missing anchor), referenced below [NOT DETECTED]
83-
#"https?:\/\/good.com"#, // BAD (missing anchor), referenced below [NOT DETECTED]
84-
"^https?://good.com" // BAD (missing post-anchor), referenced below [NOT DETECTED]
82+
"https?://good.com", // BAD (missing anchor), referenced below
83+
#"https?:\/\/good.com"#, // BAD (missing anchor), referenced below
84+
"^https?://good.com" // BAD (missing post-anchor), referenced below
8585
]
8686
for trustedUrlRegex in trustedUrlRegexs {
8787
if let _ = try NSRegularExpression(pattern: trustedUrlRegex).firstMatch(in: input, range: inputRange) { }

0 commit comments

Comments
 (0)