Skip to content

Commit b033114

Browse files
committed
Swift: sources in extension protocols.
1 parent 14468b6 commit b033114

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

swift/ql/lib/codeql/swift/dataflow/ExternalFlow.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,11 @@ private Element interpretElement0(
434434
subtypes = true and
435435
decl.getNominalTypeDecl() = nomTypeDecl.getADerivedTypeDecl*()
436436
or
437+
exists(ExtensionDecl e | e.getExtendedTypeDecl() = decl.getNominalTypeDecl() |
438+
subtypes = true and
439+
e.getAProtocol() = nomTypeDecl.getADerivedTypeDecl*()
440+
)
441+
or
437442
subtypes = false and
438443
decl.getNominalTypeDecl() = nomTypeDecl
439444
)
@@ -449,6 +454,11 @@ private Element interpretElement0(
449454
subtypes = true and
450455
decl.getNominalTypeDecl() = nomTypeDecl.getADerivedTypeDecl*()
451456
or
457+
exists(ExtensionDecl e | e.getExtendedTypeDecl() = decl.getNominalTypeDecl() |
458+
subtypes = true and
459+
e.getAProtocol() = nomTypeDecl.getADerivedTypeDecl*()
460+
)
461+
or
452462
subtypes = false and
453463
decl.getNominalTypeDecl() = nomTypeDecl
454464
)

swift/ql/test/library-tests/dataflow/flowsources/FlowSources.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
| generics.swift:93:9:93:15 | .source2 | external |
6464
| generics.swift:112:9:112:15 | .source1 | external |
6565
| generics.swift:113:9:113:15 | .source2 | external |
66+
| generics.swift:114:9:114:14 | .source1 | external |
67+
| generics.swift:115:9:115:14 | .source2 | external |
68+
| generics.swift:116:9:116:15 | .source1 | external |
69+
| generics.swift:117:9:117:15 | .source2 | external |
6670
| nsdata.swift:18:17:18:40 | call to NSData.init(contentsOf:) | external |
6771
| nsdata.swift:19:17:19:53 | call to NSData.init(contentsOf:options:) | external |
6872
| string.swift:56:21:56:44 | call to String.init(contentsOf:) | external |

swift/ql/test/library-tests/dataflow/flowsources/generics.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ extension MyImpl2 : MyProtocol2 {
111111
func useProtocol2(proto: MyProtocol2, impl: MyImpl2<Int>, impl2: MyImpl2<Any>) {
112112
_ = proto.source1 // SOURCE
113113
_ = proto.source2 // SOURCE
114-
_ = impl.source1 // SOURCE [NOT DETECTED]
115-
_ = impl.source2 // SOURCE [NOT DETECTED]
116-
_ = impl2.source1 // SOURCE [NOT DETECTED]
117-
_ = impl2.source2 // SOURCE [NOT DETECTED]
114+
_ = impl.source1 // SOURCE
115+
_ = impl.source2 // SOURCE
116+
_ = impl2.source1 // SOURCE
117+
_ = impl2.source2 // SOURCE
118118
}

0 commit comments

Comments
 (0)