File tree Expand file tree Collapse file tree 3 files changed +40
-4
lines changed
lib/codeql/swift/frameworks/StandardLibrary
test/library-tests/dataflow/taint/libraries Expand file tree Collapse file tree 3 files changed +40
-4
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Provides models the `RawRepresentable` Swift class.
3+ */
4+
5+ import swift
6+ private import codeql.swift.dataflow.DataFlow
7+ private import codeql.swift.dataflow.ExternalFlow
8+ private import codeql.swift.dataflow.FlowSteps
9+
10+ /**
11+ * A model for `RawRepresentable` class members that permit taint flow.
12+ */
13+ private class RawRepresentableSummaries extends SummaryModelCsv {
14+ override predicate row ( string row ) {
15+ row = ";RawRepresentable;true;init(rawValue:);;;Argument[0];ReturnValue;taint"
16+ }
17+ }
18+
19+ /**
20+ * A content implying that, if an `RawRepresentable` is tainted, then
21+ * the `rawValue` field is tainted as well.
22+ */
23+ private class RawRepresentableFieldsInheritTaint extends TaintInheritingContent ,
24+ DataFlow:: Content:: FieldContent
25+ {
26+ RawRepresentableFieldsInheritTaint ( ) {
27+ exists ( FieldDecl fieldDecl , Decl declaringDecl , TypeDecl namedTypeDecl |
28+ namedTypeDecl .getFullName ( ) = "RawRepresentable" and
29+ fieldDecl .getName ( ) = "rawValue" and
30+ declaringDecl .getAMember ( ) = fieldDecl and
31+ declaringDecl .asNominalTypeDecl ( ) = namedTypeDecl .getADerivedTypeDecl * ( ) and
32+ this .getField ( ) = fieldDecl
33+ )
34+ }
35+ }
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ private import NsObject
1717private import NsString
1818private import NsUrl
1919private import Numeric
20+ private import RawRepresentable
2021private import PointerTypes
2122private import Sequence
2223private import Set
Original file line number Diff line number Diff line change @@ -36,11 +36,11 @@ func testRawRepresentable() {
3636
3737 sink ( arg: rr1)
3838 sink ( arg: rr2)
39- sink ( arg: rr3) // $ MISSING: tainted=
39+ sink ( arg: rr3) // $ tainted=35
4040
4141 sink ( arg: rr1. rawValue)
4242 sink ( arg: rr2. rawValue)
43- sink ( arg: rr3. rawValue) // $ MISSING: tainted=
43+ sink ( arg: rr3. rawValue) // $ tainted=35
4444}
4545
4646// ---
@@ -57,10 +57,10 @@ func testOptionSet() {
5757 sink ( arg: MyOptionSet . red)
5858 sink ( arg: MyOptionSet ( [ . red, . green] ) )
5959 sink ( arg: MyOptionSet ( rawValue: 0 ) )
60- sink ( arg: MyOptionSet ( rawValue: sourceUInt ( ) ) ) // $ MISSING: tainted=
60+ sink ( arg: MyOptionSet ( rawValue: sourceUInt ( ) ) ) // $ tainted=60
6161
6262 sink ( arg: MyOptionSet . red. rawValue)
6363 sink ( arg: MyOptionSet ( [ . red, . green] ) . rawValue)
6464 sink ( arg: MyOptionSet ( rawValue: 0 ) . rawValue)
65- sink ( arg: MyOptionSet ( rawValue: sourceUInt ( ) ) . rawValue) // $ MISSING: tainted=
65+ sink ( arg: MyOptionSet ( rawValue: sourceUInt ( ) ) . rawValue) // $ tainted=65
6666}
You can’t perform that action at this time.
0 commit comments