Skip to content

Commit c6f2a29

Browse files
committed
Swift: Widen the StringProtocol model.
1 parent dcba1b9 commit c6f2a29

File tree

2 files changed

+8
-8
lines changed
  • swift/ql

2 files changed

+8
-8
lines changed

swift/ql/lib/codeql/swift/frameworks/StandardLibrary/String.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,18 @@ private class StringFieldsInheritTaint extends TaintInheritingContent,
138138
DataFlow::Content::FieldContent
139139
{
140140
StringFieldsInheritTaint() {
141-
this.getField()
142-
.hasQualifiedName(["String", "StringProtocol"],
141+
exists(FieldDecl fieldDecl, Decl declaringDecl, TypeDecl namedTypeDecl |
142+
(
143+
namedTypeDecl.getFullName() = ["String", "StringProtocol"] and
144+
fieldDecl.getName() =
143145
[
144146
"unicodeScalars", "utf8", "utf16", "lazy", "utf8CString", "dataValue",
145147
"identifierValue", "capitalized", "localizedCapitalized", "localizedLowercase",
146148
"localizedUppercase", "decomposedStringWithCanonicalMapping",
147149
"decomposedStringWithCompatibilityMapping", "precomposedStringWithCanonicalMapping",
148150
"precomposedStringWithCompatibilityMapping", "removingPercentEncoding"
149-
])
150-
or
151-
exists(FieldDecl fieldDecl, Decl declaringDecl, TypeDecl namedTypeDecl |
152-
(
151+
]
152+
or
153153
namedTypeDecl.getFullName() = "CustomStringConvertible" and
154154
fieldDecl.getName() = "description"
155155
or

swift/ql/test/library-tests/dataflow/taint/libraries/string.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ func testSubstringMembers() {
656656
let sub1 = tainted[..<tainted.index(tainted.endIndex, offsetBy: -5)]
657657
sink(arg: sub1) // $ tainted=654
658658
sink(arg: sub1.base) // $ MISSING: tainted=
659-
sink(arg: sub1.utf8) // $ MISSING: tainted=
659+
sink(arg: sub1.utf8) // $ tainted=654
660660
sink(arg: sub1.capitalized) // $ tainted=654
661661
sink(arg: sub1.description) // $ tainted=654
662662

@@ -670,7 +670,7 @@ func testSubstringMembers() {
670670
sink(arg: result1) // $ MISSING: tainted=
671671

672672
let sub3 = Substring(sub2.utf8)
673-
sink(arg: sub3) // $ MISSING: tainted=
673+
sink(arg: sub3) // $ tainted=654
674674

675675
var sub4 = clean.prefix(10)
676676
sink(arg: sub4)

0 commit comments

Comments
 (0)