File tree Expand file tree Collapse file tree 2 files changed +26
-7
lines changed
library-tests/dataflow/capture Expand file tree Collapse file tree 2 files changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -42,12 +42,12 @@ import codeql.swift.dataflow.TaintTracking
42
42
import TestUtilities.InlineExpectationsTest
43
43
44
44
private predicate defaultSource ( DataFlow:: Node source ) {
45
- source .asExpr ( ) .( MethodCallExpr ) .getStaticTarget ( ) .getShortName ( ) = [ "source" , "taint" ]
45
+ source .asExpr ( ) .( CallExpr ) .getStaticTarget ( ) . ( Function ) .getShortName ( ) = [ "source" , "taint" ]
46
46
}
47
47
48
48
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 ( )
51
51
)
52
52
}
53
53
@@ -67,7 +67,7 @@ private module NoFlowConfig implements DataFlow::ConfigSig {
67
67
68
68
private string getSourceArgString ( DataFlow:: Node src ) {
69
69
defaultSource ( src ) and
70
- src .asExpr ( ) .( MethodCallExpr ) .getAnArgument ( ) .getExpr ( ) .( StringLiteralExpr ) .getValue ( ) = result
70
+ src .asExpr ( ) .( CallExpr ) .getAnArgument ( ) .getExpr ( ) .( StringLiteralExpr ) .getValue ( ) = result
71
71
}
72
72
73
73
module FlowTest< DataFlow:: ConfigSig ValueFlowConfig, DataFlow:: ConfigSig TaintFlowConfig> {
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ func captureList() {
18
18
var escape : ( ( ) -> Int ) ? = nil
19
19
20
20
func setEscape( ) {
21
- var x = source ( " setEscape " , 0 )
21
+ let x = source ( " setEscape " , 0 )
22
22
escape = {
23
23
sink ( x) // $ MISSING: hasValueFlow=setEscape
24
24
return x + 1
@@ -31,11 +31,15 @@ func callEscape() {
31
31
}
32
32
33
33
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
+
35
39
let x : Int ? = source ( " logical " , 42 )
36
40
return f != nil
37
41
&& ( x != nil
38
- && f!( x!) == 43 ) // $ MISSING: hasValueFlow=logical
42
+ && f!( x!) == 43 )
39
43
}
40
44
41
45
func asyncTest( ) {
@@ -121,6 +125,21 @@ func sharedCaptureMultipleWriters() {
121
125
callSink2 ( )
122
126
}
123
127
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
+ }
124
143
125
144
func main( ) {
126
145
print ( " captureList(): " )
You can’t perform that action at this time.
0 commit comments