Skip to content

Commit af79139

Browse files
authored
Merge pull request github#10772 from atorralba/atorralba/swift/subscriptexpr-taint-step
Swift: Add taint step for subscript expressions
2 parents 7ac9c1e + 0892a57 commit af79139

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ private module Cached {
4949
ae.getType().getName() = "String"
5050
)
5151
or
52+
// flow through a subscript access
53+
exists(SubscriptExpr se |
54+
se.getBase() = nodeFrom.asExpr() and
55+
se = nodeTo.asExpr()
56+
)
57+
or
5258
// flow through a flow summary (extension of `SummaryModelCsv`)
5359
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom, nodeTo, false)
5460
}

swift/ql/test/library-tests/dataflow/taint/LocalTaint.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,5 @@
123123
| string.swift:39:13:39:19 | ... .+(_:_:) ... | string.swift:39:13:39:29 | ... .+(_:_:) ... |
124124
| string.swift:39:19:39:19 | tainted | string.swift:39:13:39:19 | ... .+(_:_:) ... |
125125
| string.swift:39:29:39:29 | < | string.swift:39:13:39:29 | ... .+(_:_:) ... |
126+
| subscript.swift:13:10:13:17 | call to source() | subscript.swift:13:10:13:20 | ...[...] |
127+
| subscript.swift:14:10:14:18 | call to source2() | subscript.swift:14:10:14:21 | ...[...] |

swift/ql/test/library-tests/dataflow/taint/Taint.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ edges
1010
| string.swift:28:17:28:25 | call to source2() : | string.swift:35:13:35:23 | ... .+(_:_:) ... |
1111
| string.swift:28:17:28:25 | call to source2() : | string.swift:36:13:36:23 | ... .+(_:_:) ... |
1212
| string.swift:28:17:28:25 | call to source2() : | string.swift:39:13:39:29 | ... .+(_:_:) ... |
13+
| subscript.swift:13:10:13:17 | call to source() : | subscript.swift:13:10:13:20 | ...[...] |
14+
| subscript.swift:14:10:14:18 | call to source2() : | subscript.swift:14:10:14:21 | ...[...] |
1315
| try.swift:9:17:9:24 | call to source() : | try.swift:9:13:9:24 | try ... |
1416
| try.swift:15:17:15:24 | call to source() : | try.swift:15:12:15:24 | try! ... |
1517
| try.swift:18:18:18:25 | call to source() : | try.swift:18:12:18:27 | ...! |
@@ -65,6 +67,10 @@ nodes
6567
| string.swift:35:13:35:23 | ... .+(_:_:) ... | semmle.label | ... .+(_:_:) ... |
6668
| string.swift:36:13:36:23 | ... .+(_:_:) ... | semmle.label | ... .+(_:_:) ... |
6769
| string.swift:39:13:39:29 | ... .+(_:_:) ... | semmle.label | ... .+(_:_:) ... |
70+
| subscript.swift:13:10:13:17 | call to source() : | semmle.label | call to source() : |
71+
| subscript.swift:13:10:13:20 | ...[...] | semmle.label | ...[...] |
72+
| subscript.swift:14:10:14:18 | call to source2() : | semmle.label | call to source2() : |
73+
| subscript.swift:14:10:14:21 | ...[...] | semmle.label | ...[...] |
6874
| try.swift:9:13:9:24 | try ... | semmle.label | try ... |
6975
| try.swift:9:17:9:24 | call to source() : | semmle.label | call to source() : |
7076
| try.swift:15:12:15:24 | try! ... | semmle.label | try! ... |
@@ -115,6 +121,8 @@ subpaths
115121
| string.swift:35:13:35:23 | ... .+(_:_:) ... | string.swift:28:17:28:25 | call to source2() : | string.swift:35:13:35:23 | ... .+(_:_:) ... | result |
116122
| string.swift:36:13:36:23 | ... .+(_:_:) ... | string.swift:28:17:28:25 | call to source2() : | string.swift:36:13:36:23 | ... .+(_:_:) ... | result |
117123
| string.swift:39:13:39:29 | ... .+(_:_:) ... | string.swift:28:17:28:25 | call to source2() : | string.swift:39:13:39:29 | ... .+(_:_:) ... | result |
124+
| subscript.swift:13:10:13:20 | ...[...] | subscript.swift:13:10:13:17 | call to source() : | subscript.swift:13:10:13:20 | ...[...] | result |
125+
| subscript.swift:14:10:14:21 | ...[...] | subscript.swift:14:10:14:18 | call to source2() : | subscript.swift:14:10:14:21 | ...[...] | result |
118126
| try.swift:9:13:9:24 | try ... | try.swift:9:17:9:24 | call to source() : | try.swift:9:13:9:24 | try ... | result |
119127
| try.swift:15:12:15:24 | try! ... | try.swift:15:17:15:24 | call to source() : | try.swift:15:12:15:24 | try! ... | result |
120128
| try.swift:18:12:18:27 | ...! | try.swift:18:18:18:25 | call to source() : | try.swift:18:12:18:27 | ...! | result |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class SubscriptTest {
2+
subscript(index: Int) -> String {
3+
get { return "" }
4+
set(newValue) {}
5+
}
6+
}
7+
8+
func source() -> Array<String> { return [""] }
9+
func source2() -> SubscriptTest { return SubscriptTest() }
10+
func sink(arg: String) {}
11+
12+
func test() {
13+
sink(source()[0]) // $ tainted=13
14+
sink(source2()[0]) // $ tainted=14
15+
}

0 commit comments

Comments
 (0)