Skip to content

Commit 7f9cb16

Browse files
committed
Swift: Add a test with multiple evaluations.
1 parent cb4139f commit 7f9cb16

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

swift/ql/test/query-tests/Security/CWE-730/RegexInjection.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ edges
1919
| tests.swift:95:22:95:46 | call to String.init(contentsOf:) | tests.swift:179:17:179:17 | taintedString |
2020
| tests.swift:95:22:95:46 | call to String.init(contentsOf:) | tests.swift:182:17:182:17 | taintedString |
2121
| tests.swift:95:22:95:46 | call to String.init(contentsOf:) | tests.swift:185:17:185:17 | taintedString |
22+
| tests.swift:95:22:95:46 | call to String.init(contentsOf:) | tests.swift:190:21:190:21 | taintedString |
2223
nodes
2324
| tests.swift:95:22:95:46 | call to String.init(contentsOf:) | semmle.label | call to String.init(contentsOf:) |
2425
| tests.swift:101:16:101:16 | taintedString | semmle.label | taintedString |
@@ -41,6 +42,7 @@ nodes
4142
| tests.swift:179:17:179:17 | taintedString | semmle.label | taintedString |
4243
| tests.swift:182:17:182:17 | taintedString | semmle.label | taintedString |
4344
| tests.swift:185:17:185:17 | taintedString | semmle.label | taintedString |
45+
| tests.swift:190:21:190:21 | taintedString | semmle.label | taintedString |
4446
subpaths
4547
#select
4648
| tests.swift:101:16:101:16 | taintedString | tests.swift:95:22:95:46 | call to String.init(contentsOf:) | tests.swift:101:16:101:16 | taintedString | This regular expression is constructed from a $@. | tests.swift:95:22:95:46 | call to String.init(contentsOf:) | user-provided value |
@@ -63,3 +65,4 @@ subpaths
6365
| tests.swift:179:17:179:17 | taintedString | tests.swift:95:22:95:46 | call to String.init(contentsOf:) | tests.swift:179:17:179:17 | taintedString | This regular expression is constructed from a $@. | tests.swift:95:22:95:46 | call to String.init(contentsOf:) | user-provided value |
6466
| tests.swift:182:17:182:17 | taintedString | tests.swift:95:22:95:46 | call to String.init(contentsOf:) | tests.swift:182:17:182:17 | taintedString | This regular expression is constructed from a $@. | tests.swift:95:22:95:46 | call to String.init(contentsOf:) | user-provided value |
6567
| tests.swift:185:17:185:17 | taintedString | tests.swift:95:22:95:46 | call to String.init(contentsOf:) | tests.swift:185:17:185:17 | taintedString | This regular expression is constructed from a $@. | tests.swift:95:22:95:46 | call to String.init(contentsOf:) | user-provided value |
68+
| tests.swift:190:21:190:21 | taintedString | tests.swift:95:22:95:46 | call to String.init(contentsOf:) | tests.swift:190:21:190:21 | taintedString | This regular expression is constructed from a $@. | tests.swift:95:22:95:46 | call to String.init(contentsOf:) | user-provided value |

swift/ql/test/query-tests/Security/CWE-730/tests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,10 @@ func regexInjectionTests(cond: Bool, varString: String, myUrl: URL) throws {
184184
if (okSet.contains(taintedString)) {
185185
_ = try Regex(taintedString).firstMatch(in: varString) // GOOD (effectively sanitized by the check) [FALSE POSITIVE]
186186
}
187+
188+
// --- multiple evaluations ---
189+
190+
let re = try Regex(taintedString) // BAD
191+
_ = try re.firstMatch(in: varString) // (we only want to flag one location total)
192+
_ = try re.firstMatch(in: varString)
187193
}

0 commit comments

Comments
 (0)