Skip to content

Commit 5418d39

Browse files
d10cMathiasVP
authored andcommitted
Swift: add and accept a few new simple test cases
1 parent af49a3a commit 5418d39

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

swift/ql/test/TestUtilities/InlineFlowTest.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ import codeql.swift.dataflow.TaintTracking
4242
import TestUtilities.InlineExpectationsTest
4343

4444
private predicate defaultSource(DataFlow::Node source) {
45-
source.asExpr().(MethodCallExpr).getStaticTarget().getShortName() = ["source", "taint"]
45+
source.asExpr().(CallExpr).getStaticTarget().(Function).getShortName() = ["source", "taint"]
4646
}
4747

4848
private predicate defaultSink(DataFlow::Node sink) {
49-
exists(MethodCallExpr ma | ma.getStaticTarget().getShortName() = "sink" |
50-
sink.asExpr() = ma.getAnArgument().getExpr()
49+
exists(CallExpr ca | ca.getStaticTarget().(Function).getShortName() = "sink" |
50+
sink.asExpr() = ca.getAnArgument().getExpr()
5151
)
5252
}
5353

@@ -67,7 +67,7 @@ private module NoFlowConfig implements DataFlow::ConfigSig {
6767

6868
private string getSourceArgString(DataFlow::Node src) {
6969
defaultSource(src) and
70-
src.asExpr().(MethodCallExpr).getAnArgument().getExpr().(StringLiteralExpr).getValue() = result
70+
src.asExpr().(CallExpr).getAnArgument().getExpr().(StringLiteralExpr).getValue() = result
7171
}
7272

7373
module FlowTest<DataFlow::ConfigSig ValueFlowConfig, DataFlow::ConfigSig TaintFlowConfig> {

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func captureList() {
1818
var escape: (() -> Int)? = nil
1919

2020
func setEscape() {
21-
var x = source("setEscape", 0)
21+
let x = source("setEscape", 0)
2222
escape = {
2323
sink(x) // $ MISSING: hasValueFlow=setEscape
2424
return x + 1
@@ -31,11 +31,15 @@ func callEscape() {
3131
}
3232

3333
func logical() -> Bool {
34-
let f: ((Int) -> Int)? = { x in x + 1 }
34+
let f: ((Int) -> Int)? = { x in
35+
sink(x) // $ hasValueFlow=logical
36+
return x + 1
37+
}
38+
3539
let x: Int? = source("logical", 42)
3640
return f != nil
3741
&& (x != nil
38-
&& f!(x!) == 43) // $ MISSING: hasValueFlow=logical
42+
&& f!(x!) == 43)
3943
}
4044

4145
func asyncTest() {
@@ -121,6 +125,21 @@ func sharedCaptureMultipleWriters() {
121125
callSink2()
122126
}
123127

128+
func taintCollections(array: inout Array<Int>) {
129+
array[0] = source("array", 0)
130+
sink(array)
131+
sink(array[0]) // $ hasValueFlow=array
132+
array.withContiguousStorageIfAvailable({
133+
buffer in
134+
sink(array)
135+
sink(array[0]) // $ hasValueFlow=array
136+
})
137+
}
138+
139+
func simplestTest() {
140+
let x = source("simplestTest", 0)
141+
sink(x) // $ hasValueFlow=simplestTest
142+
}
124143

125144
func main() {
126145
print("captureList():")

0 commit comments

Comments
 (0)