File tree Expand file tree Collapse file tree 3 files changed +25
-6
lines changed
lib/codeql/swift/frameworks
test/library-tests/dataflow/taint/libraries Expand file tree Collapse file tree 3 files changed +25
-6
lines changed Original file line number Diff line number Diff line change 66import swift
77private import codeql.swift.dataflow.DataFlow
88private import codeql.swift.dataflow.FlowSources
9+ private import codeql.swift.dataflow.FlowSteps
910
1011/**
1112 * An initializer call `ce` that has a "contentsOf" argument, along with a
@@ -51,3 +52,21 @@ private class InitializerContentsOfLocalSource extends LocalFlowSource {
5152
5253 override string getSourceType ( ) { result = "contentsOf initializer" }
5354}
55+
56+ /**
57+ * An imprecise flow step for an initializer call with a "data" argument. For
58+ * example:
59+ * ```
60+ * let mc = MyClass(data: taintedData)
61+ * ```
62+ */
63+ private class InitializerFromDataStep extends AdditionalTaintStep {
64+ override predicate step ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
65+ exists ( InitializerCallExpr ce , Argument arg |
66+ ce .getAnArgument ( ) = arg and
67+ arg .getLabel ( ) = "data" and
68+ node1 .asExpr ( ) = arg .getExpr ( ) and
69+ node2 .asExpr ( ) = ce
70+ )
71+ }
72+ }
Original file line number Diff line number Diff line change @@ -44,10 +44,10 @@ func testCustom() {
4444 let tainted2 = MyContainer ( data: source ( " data2 " ) , flags: 123 )
4545 sink ( arg: clean)
4646 sink ( arg: clean [ 0 ] )
47- sink ( arg: tainted) // $ MISSING: tainted=data1
48- sink ( arg: tainted [ 0 ] ) // $ MISSING: tainted=data1
49- sink ( arg: tainted2) // $ MISSING: tainted=data2
50- sink ( arg: tainted2 [ 0 ] ) // $ MISSING: tainted=data2
47+ sink ( arg: tainted) // $ tainted=data1
48+ sink ( arg: tainted [ 0 ] ) // $ tainted=data1
49+ sink ( arg: tainted2) // $ tainted=data2
50+ sink ( arg: tainted2 [ 0 ] ) // $ tainted=data2
5151
5252 var mc1 = MyContainer ( )
5353 mc1. append ( Data ( 0 ) )
Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ func testUIImage(scale: CGFloat) {
9191 let taintedData = source ( " UIImage " ) as! Data
9292
9393 sink ( UIImage ( data: Data ( 0 ) ) !)
94- sink ( UIImage ( data: Data ( taintedData) ) !) // $ MISSING: tainted=UIImage
94+ sink ( UIImage ( data: Data ( taintedData) ) !) // $ tainted=UIImage
9595 sink ( UIImage ( data: Data ( 0 ) , scale: scale) !)
96- sink ( UIImage ( data: Data ( taintedData) , scale: scale) !) // $ MISSING: tainted=UIImage
96+ sink ( UIImage ( data: Data ( taintedData) , scale: scale) !) // $ tainted=UIImage
9797}
You can’t perform that action at this time.
0 commit comments