File tree Expand file tree Collapse file tree
library-tests/dataflow/capture Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,12 +42,12 @@ import codeql.swift.dataflow.TaintTracking
4242import TestUtilities.InlineExpectationsTest
4343
4444private predicate defaultSource ( DataFlow:: Node source ) {
45- source .asExpr ( ) .( MethodCallExpr ) .getStaticTarget ( ) .getShortName ( ) = [ "source" , "taint" ]
45+ source .asExpr ( ) .( CallExpr ) .getStaticTarget ( ) . ( Function ) .getShortName ( ) = [ "source" , "taint" ]
4646}
4747
4848private 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
6868private 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
7373module FlowTest< DataFlow:: ConfigSig ValueFlowConfig, DataFlow:: ConfigSig TaintFlowConfig> {
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ func captureList() {
1818var escape : ( ( ) -> Int ) ? = nil
1919
2020func 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
3333func 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
4145func 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
125144func main( ) {
126145 print ( " captureList(): " )
You can’t perform that action at this time.
0 commit comments