Swift: Use FieldDecl.hasQualifiedName.

This commit is contained in:
Geoffrey White
2023-06-02 11:44:47 +01:00
parent 5bf82aeddf
commit c7c8807f40
6 changed files with 31 additions and 48 deletions

View File

@@ -47,9 +47,8 @@ private class CollectionFieldsInheritTaint extends TaintInheritingContent,
DataFlow::Content::FieldContent
{
CollectionFieldsInheritTaint() {
exists(FieldDecl f | this.getField() = f |
f.getEnclosingDecl().asNominalTypeDecl().getName() = ["Collection", "BidirectionalCollection"] and
f.getName() = ["first", "last"]
)
this.getField()
.(FieldDecl)
.hasQualifiedName(["Collection", "BidirectionalCollection"], ["first", "last"])
}
}

View File

@@ -132,20 +132,19 @@ private class NsStringFieldsInheritTaint extends TaintInheritingContent,
DataFlow::Content::FieldContent
{
NsStringFieldsInheritTaint() {
exists(FieldDecl f | this.getField() = f |
f.getEnclosingDecl().asNominalTypeDecl().getName() = "NSString" and
f.getName() =
[
"utf8String", "lowercased", "localizedLowedCase", "uppercased", "localizedUppercase",
"capitalized", "localizedCapitalized", "decomposedStringWithCanonicalMapping",
"decomposedStringWithCompatibilityMapping", "precomposedStringWithCanonicalMapping",
"precomposedStringWithCompatibilityMapping", "doubleValue", "floatValue", "intValue",
"integerValue", "longLongValue", "boolValue", "description", "pathComponents",
"fileSystemRepresentation", "lastPathComponent", "pathExtension",
"abbreviatingWithTildeInPath", "deletingLastPathComponent", "deletingPathExtension",
"expandingTildeInPath", "resolvingSymlinksInPath", "standardizingPath",
"removingPercentEncoding"
]
)
this.getField()
.(FieldDecl)
.hasQualifiedName("NSString",
[
"utf8String", "lowercased", "localizedLowedCase", "uppercased", "localizedUppercase",
"capitalized", "localizedCapitalized", "decomposedStringWithCanonicalMapping",
"decomposedStringWithCompatibilityMapping", "precomposedStringWithCanonicalMapping",
"precomposedStringWithCompatibilityMapping", "doubleValue", "floatValue", "intValue",
"integerValue", "longLongValue", "boolValue", "description", "pathComponents",
"fileSystemRepresentation", "lastPathComponent", "pathExtension",
"abbreviatingWithTildeInPath", "deletingLastPathComponent", "deletingPathExtension",
"expandingTildeInPath", "resolvingSymlinksInPath", "standardizingPath",
"removingPercentEncoding"
])
}
}

View File

@@ -36,10 +36,5 @@ private class SequenceSummaries extends SummaryModelCsv {
private class SequenceFieldsInheritTaint extends TaintInheritingContent,
DataFlow::Content::FieldContent
{
SequenceFieldsInheritTaint() {
exists(FieldDecl f | this.getField() = f |
f.getEnclosingDecl().asNominalTypeDecl().getName() = "Sequence" and
f.getName() = "lazy"
)
}
SequenceFieldsInheritTaint() { this.getField().(FieldDecl).hasQualifiedName("Sequence", "lazy") }
}

View File

@@ -124,16 +124,16 @@ private class StringFieldsInheritTaint extends TaintInheritingContent,
DataFlow::Content::FieldContent
{
StringFieldsInheritTaint() {
exists(FieldDecl f | this.getField() = f |
f.getEnclosingDecl().asNominalTypeDecl().getName() = ["String", "StringProtocol"] and
f.getName() =
[
"unicodeScalars", "utf8", "utf16", "lazy", "utf8CString", "description",
"debugDescription", "dataValue", "identifierValue", "capitalized", "localizedCapitalized",
"localizedLowercase", "localizedUppercase", "decomposedStringWithCanonicalMapping",
"decomposedStringWithCompatibilityMapping", "precomposedStringWithCanonicalMapping",
"precomposedStringWithCompatibilityMapping", "removingPercentEncoding"
]
)
this.getField()
.(FieldDecl)
.hasQualifiedName(["String", "StringProtocol"],
[
"unicodeScalars", "utf8", "utf16", "lazy", "utf8CString", "description",
"debugDescription", "dataValue", "identifierValue", "capitalized",
"localizedCapitalized", "localizedLowercase", "localizedUppercase",
"decomposedStringWithCanonicalMapping", "decomposedStringWithCompatibilityMapping",
"precomposedStringWithCanonicalMapping", "precomposedStringWithCompatibilityMapping",
"removingPercentEncoding"
])
}
}

View File

@@ -208,10 +208,5 @@ private class WKUserScriptSummaries extends SummaryModelCsv {
private class WKUserScriptInheritsTaint extends TaintInheritingContent,
DataFlow::Content::FieldContent
{
WKUserScriptInheritsTaint() {
exists(FieldDecl f | this.getField() = f |
f.getEnclosingDecl().asNominalTypeDecl().getName() = "WKUserScript" and
f.getName() = "source"
)
}
WKUserScriptInheritsTaint() { this.getField().hasQualifiedName("WKUserScript", "source") }
}

View File

@@ -74,12 +74,7 @@ private class OsLogNonRedactedType extends Type {
private class OsLogPrivacyRef extends MemberRefExpr {
string optionName;
OsLogPrivacyRef() {
exists(FieldDecl f | this.getMember() = f |
f.getEnclosingDecl().asNominalTypeDecl().getName() = "OSLogPrivacy" and
optionName = f.getName()
)
}
OsLogPrivacyRef() { this.getMember().(FieldDecl).hasQualifiedName("OSLogPrivacy", optionName) }
/** Holds if this is a safe privacy option (private or sensitive). */
predicate isSafe() { optionName = ["private", "sensitive"] }