Skip to content

Commit 086002f

Browse files
committed
Swift: Add a general model for description, debugDescription.
1 parent f12e45b commit 086002f

File tree

2 files changed

+18
-3
lines changed
  • swift/ql

2 files changed

+18
-3
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,20 @@ private class StringFieldsInheritTaint extends TaintInheritingContent,
147147
"decomposedStringWithCompatibilityMapping", "precomposedStringWithCanonicalMapping",
148148
"precomposedStringWithCompatibilityMapping", "removingPercentEncoding"
149149
])
150+
or
151+
exists(FieldDecl fieldDecl, Decl declaringDecl, TypeDecl namedTypeDecl |
152+
(
153+
(
154+
namedTypeDecl.getFullName() = "CustomStringConvertible" and
155+
fieldDecl.getName() = "description"
156+
) or (
157+
namedTypeDecl.getFullName() = "CustomDebugStringConvertible" and
158+
fieldDecl.getName() = "debugDescription"
159+
)
160+
) and
161+
declaringDecl.getAMember() = fieldDecl and
162+
declaringDecl.asNominalTypeDecl() = namedTypeDecl.getADerivedTypeDecl*() and
163+
this.getField() = fieldDecl
164+
)
150165
}
151166
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ func taintThroughSimpleStringOperations() {
272272
sink(arg: [tainted, tainted].joined()) // $ MISSING: tainted=217
273273

274274
sink(arg: clean.description)
275-
sink(arg: tainted.description) // $ MISSING: tainted=217
275+
sink(arg: tainted.description) // $ tainted=217
276276
sink(arg: clean.debugDescription)
277-
sink(arg: tainted.debugDescription) // $ MISSING: tainted=217
277+
sink(arg: tainted.debugDescription) // $ tainted=217
278278
sink(arg: clean.utf8)
279279
sink(arg: tainted.utf8) // $ tainted=217
280280
sink(arg: clean.utf16)
@@ -584,7 +584,7 @@ func taintedThroughConversion() {
584584
sink(arg: String(0))
585585
sink(arg: String(source())) // $ tainted=585
586586
sink(arg: Int(0).description)
587-
sink(arg: source().description) // $ MISSING: tainted=587
587+
sink(arg: source().description) // $ tainted=587
588588
sink(arg: String(describing: 0))
589589
sink(arg: String(describing: source())) // $ tainted=589
590590

0 commit comments

Comments
 (0)