Skip to content

Commit 93c39c5

Browse files
committed
Swift: Add data flow through OpenExistentialExpr.
1 parent b8d29e8 commit 93c39c5

File tree

5 files changed

+10
-2
lines changed

5 files changed

+10
-2
lines changed

swift/ql/lib/codeql/swift/dataflow/internal/DataFlowPrivate.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ private module Cached {
208208
nodeFrom.asExpr() = ie.getBranch(_)
209209
)
210210
or
211+
// flow through OpenExistentialExpr (compiler generated expression wrapper)
212+
nodeFrom.asExpr() = nodeTo.asExpr().(OpenExistentialExpr).getSubExpr()
213+
or
211214
// flow from Expr to Pattern
212215
exists(Expr e, Pattern p |
213216
nodeFrom.asExpr() = e and

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ edges
438438
| test.swift:766:29:766:29 | KeyPathComponent [x] | test.swift:766:13:766:29 | exit #keyPath(...) |
439439
| test.swift:767:15:767:15 | s2 [s, some:0, x] | test.swift:766:13:766:29 | enter #keyPath(...) [s, some:0, x] |
440440
| test.swift:767:15:767:15 | s2 [s, some:0, x] | test.swift:767:15:767:28 | \\...[...] |
441+
| test.swift:775:12:775:21 | call to source() | test.swift:775:12:775:21 | OpenExistentialExpr |
441442
nodes
442443
| file://:0:0:0:0 | .a [x] | semmle.label | .a [x] |
443444
| file://:0:0:0:0 | .str | semmle.label | .str |
@@ -915,6 +916,8 @@ nodes
915916
| test.swift:766:29:766:29 | KeyPathComponent [x] | semmle.label | KeyPathComponent [x] |
916917
| test.swift:767:15:767:15 | s2 [s, some:0, x] | semmle.label | s2 [s, some:0, x] |
917918
| test.swift:767:15:767:28 | \\...[...] | semmle.label | \\...[...] |
919+
| test.swift:775:12:775:21 | OpenExistentialExpr | semmle.label | OpenExistentialExpr |
920+
| test.swift:775:12:775:21 | call to source() | semmle.label | call to source() |
918921
subpaths
919922
| test.swift:75:22:75:22 | x | test.swift:65:16:65:28 | arg1 | test.swift:65:1:70:1 | arg2[return] | test.swift:75:32:75:32 | [post] y |
920923
| 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 ... |
@@ -1070,3 +1073,4 @@ subpaths
10701073
| test.swift:756:15:756:21 | ...! | test.swift:746:14:746:21 | call to source() | test.swift:756:15:756:21 | ...! | result |
10711074
| test.swift:757:15:757:19 | .v3 | test.swift:747:14:747:21 | call to source() | test.swift:757:15:757:19 | .v3 | result |
10721075
| test.swift:767:15:767:28 | \\...[...] | test.swift:764:18:764:25 | call to source() | test.swift:767:15:767:28 | \\...[...] | result |
1076+
| test.swift:775:12:775:21 | OpenExistentialExpr | test.swift:775:12:775:21 | call to source() | test.swift:775:12:775:21 | OpenExistentialExpr | result |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,3 +926,4 @@
926926
| test.swift:766:13:766:29 | enter #keyPath(...) | test.swift:766:26:766:26 | KeyPathComponent |
927927
| test.swift:774:30:774:33 | SSA def(x) | test.swift:775:12:775:12 | x |
928928
| test.swift:774:30:774:33 | x | test.swift:774:30:774:33 | SSA def(x) |
929+
| test.swift:775:12:775:21 | call to source() | test.swift:775:12:775:21 | OpenExistentialExpr |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,5 +772,5 @@ protocol MyProtocol {
772772
}
773773

774774
func testOpenExistentialExpr(x: MyProtocol) {
775-
sink(arg: x.source()) // $ MISSING:flow=771
775+
sink(arg: x.source()) // $ flow=775
776776
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,5 @@ func test(
8686
_ = myTextInput.harmless(in: range)! // GOOD (not input)
8787

8888
let str = protocolTextInput.text(in: range)! // $ source=local
89-
sink(arg: str) // $ MISSING: tainted
89+
sink(arg: str) // $ tainted
9090
}

0 commit comments

Comments
 (0)