Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
category: deprecated
---

* The `ArrayContent` type in the data flow library has been deprecated and made an alias for the `CollectionContent` type, to better reflect the hierarchy of the Swift standard library. Uses of `ArrayElement` in model files will be interpreted as referring to `CollectionContent`.
3 changes: 2 additions & 1 deletion swift/ql/lib/codeql/swift/dataflow/ExternalFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,9 @@ predicate parseContent(AccessPathToken component, Content content) {
or
parseEnum(component, content)
or
// map legacy "ArrayElement" specification components to `CollectionContent`
component.getName() = "ArrayElement" and
Comment thread
rdmarsh2 marked this conversation as resolved.
content instanceof Content::ArrayContent
content instanceof Content::CollectionContent
or
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I suggest we don't delete this case, but make it a synonym for CollectionElement. We can carefully ensure we're not using it ourselves, but that way we'll avoid breaking any user code that uses ArrayElement.

component.getName() = "CollectionElement" and
content instanceof Content::CollectionContent
Expand Down
18 changes: 5 additions & 13 deletions swift/ql/lib/codeql/swift/dataflow/internal/DataFlowPrivate.qll
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ private module Cached {
TFieldContent(FieldDecl f) or
TTupleContent(int index) { exists(any(TupleExpr te).getElement(index)) } or
TEnumContent(ParamDecl f) { exists(EnumElementDecl d | d.getAParam() = f) } or
TArrayContent() or
TCollectionContent()
}

Expand Down Expand Up @@ -842,7 +841,7 @@ predicate storeStep(Node node1, ContentSet c, Node node2) {
exists(ArrayExpr arr |
node1.asExpr() = arr.getAnElement() and
node2.asExpr() = arr and
c.isSingleton(any(Content::ArrayContent ac))
c.isSingleton(any(Content::CollectionContent ac))
)
or
// array assignment `a[n] = x`
Expand All @@ -851,7 +850,7 @@ predicate storeStep(Node node1, ContentSet c, Node node2) {
node2.(PostUpdateNode).getPreUpdateNode().asExpr() = subscript.getBase() and
subscript = assign.getDest() and
subscript.getBase().getType() instanceof ArrayType and
c.isSingleton(any(Content::ArrayContent ac))
c.isSingleton(any(Content::CollectionContent ac))
)
or
// creation of an optional via implicit wrapping keypath component
Expand Down Expand Up @@ -948,7 +947,7 @@ predicate readStep(Node node1, ContentSet c, Node node2) {
(
c.isSingleton(any(Content::FieldContent ct | ct.getField() = component.getDeclRef()))
or
c.isSingleton(any(Content::ArrayContent ac)) and
c.isSingleton(any(Content::CollectionContent ac)) and
component.isSubscript()
or
c instanceof OptionalSomeContentSet and
Expand All @@ -971,12 +970,7 @@ predicate readStep(Node node1, ContentSet c, Node node2) {
exists(SubscriptExpr subscript |
subscript.getBase() = node1.asExpr() and
subscript = node2.asExpr() and
(
subscript.getBase().getType() instanceof ArrayType and
c.isSingleton(any(Content::ArrayContent ac))
or
c.isSingleton(any(Content::CollectionContent ac))
)
c.isSingleton(any(Content::CollectionContent ac))
)
or
// read of a dictionary value via subscript operator
Expand Down Expand Up @@ -1098,9 +1092,7 @@ class DataFlowExpr = Expr;
* Holds if access paths with `c` at their head always should be tracked at high
* precision. This disables adaptive access path precision for such access paths.
*/
predicate forceHighPrecision(Content c) {
c instanceof Content::ArrayContent or c instanceof Content::CollectionContent
}
predicate forceHighPrecision(Content c) { c instanceof Content::CollectionContent }

/**
* Holds if the node `n` is unreachable when the call context is `call`.
Expand Down
10 changes: 5 additions & 5 deletions swift/ql/lib/codeql/swift/dataflow/internal/DataFlowPublic.qll
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,6 @@ module Content {
override string toString() { result = this.getSignature() }
}

/** An element of an array at an unknown index */
class ArrayContent extends Content, TArrayContent {
override string toString() { result = "Array element" }
}

/**
* An element of a collection. This is a broad class including:
* - elements of collections, such as `Set<Element>`.
Expand All @@ -234,6 +229,11 @@ module Content {
class CollectionContent extends Content, TCollectionContent {
override string toString() { result = "Collection element" }
}

/**
* DEPRECATED: An element of a collection. This is an alias for the general CollectionContent.
*/
deprecated class ArrayContent = CollectionContent;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,6 @@ private string getContentSpecific(ContentSet cs) {
result = "EnumElement[" + c.getSignature() + "]"
)
or
exists(Content::ArrayContent c |
cs.isSingleton(c) and
result = "ArrayElement"
)
or
exists(Content::CollectionContent c |
cs.isSingleton(c) and
result = "CollectionElement"
Expand Down
10 changes: 5 additions & 5 deletions swift/ql/lib/codeql/swift/frameworks/StandardLibrary/Array.qll
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ private class ArraySummaries extends SummaryModelCsv {
override predicate row(string row) {
row =
[
";Array;true;insert(_:at:);;;Argument[0];Argument[-1].ArrayElement;value",
";Array;true;insert(_:at:);;;Argument[0];Argument[-1].CollectionElement;value",
";Array;true;insert(_:at:);;;Argument[1];Argument[-1];taint",
";Array;true;withUnsafeBufferPointer(_:);;;Argument[-1];Argument[0].Parameter[0].CollectionElement;taint",
";Array;true;withUnsafeBufferPointer(_:);;;Argument[-1].ArrayElement;Argument[0].Parameter[0].CollectionElement;value",
";Array;true;withUnsafeBufferPointer(_:);;;Argument[-1].CollectionElement;Argument[0].Parameter[0].CollectionElement;value",
";Array;true;withUnsafeBufferPointer(_:);;;Argument[0].ReturnValue;ReturnValue;value",
";Array;true;withUnsafeMutableBufferPointer(_:);;;Argument[-1];Argument[0].Parameter[0].CollectionElement;taint",
";Array;true;withUnsafeMutableBufferPointer(_:);;;Argument[-1].ArrayElement;Argument[0].Parameter[0].CollectionElement;value",
";Array;true;withUnsafeMutableBufferPointer(_:);;;Argument[-1].CollectionElement;Argument[0].Parameter[0].CollectionElement;value",
";Array;true;withUnsafeMutableBufferPointer(_:);;;Argument[0].Parameter[0].CollectionElement;Argument[-1].CollectionElement;value",
";Array;true;withUnsafeMutableBufferPointer(_:);;;Argument[0].ReturnValue;ReturnValue;value",
";Array;true;withUnsafeBytes(_:);;;Argument[-1];Argument[0].Parameter[0].CollectionElement;taint",
";Array;true;withUnsafeBytes(_:);;;Argument[-1].ArrayElement;Argument[0].Parameter[0].CollectionElement;taint",
";Array;true;withUnsafeBytes(_:);;;Argument[-1].CollectionElement;Argument[0].Parameter[0].CollectionElement;taint",
";Array;true;withUnsafeBytes(_:);;;Argument[0].ReturnValue;ReturnValue;value",
";Array;true;withUnsafeMutableBytes(_:);;;Argument[-1];Argument[0].Parameter[0].CollectionElement;taint",
";Array;true;withUnsafeMutableBytes(_:);;;Argument[-1].ArrayElement;Argument[0].Parameter[0].CollectionElement;taint",
";Array;true;withUnsafeMutableBytes(_:);;;Argument[-1].CollectionElement;Argument[0].Parameter[0].CollectionElement;taint",
";Array;true;withUnsafeMutableBytes(_:);;;Argument[0].Parameter[0].CollectionElement;Argument[-1].CollectionElement;value",
";Array;true;withUnsafeMutableBytes(_:);;;Argument[0].ReturnValue;ReturnValue;value",
";ContiguousArray;true;withUnsafeBufferPointer(_:);;;Argument[-1];Argument[0].Parameter[0].CollectionElement;taint",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ private class CollectionSummaries extends SummaryModelCsv {
";Collection;true;removeFirst();;;Argument[-1];ReturnValue;taint",
";Collection;true;popFirst();;;Argument[-1];ReturnValue;taint",
";Collection;true;randomElement();;;Argument[-1].CollectionElement;ReturnValue.OptionalSome;value",
";Collection;true;randomElement();;;Argument[-1].ArrayElement;ReturnValue.OptionalSome;value",
";RangeReplaceableCollection;true;append(_:);;;Argument[0];Argument[-1];taint",
";RangeReplaceableCollection;true;append(contentsOf:);;;Argument[0];Argument[-1];taint",
";RangeReplaceableCollection;true;remove(at:);;;Argument[-1];ReturnValue;taint",
Expand All @@ -38,7 +37,6 @@ private class CollectionSummaries extends SummaryModelCsv {
";BidirectionalCollection;true;last(where:);;;Argument[-1];ReturnValue;taint",
";BidirectionalCollection;true;popLast();;;Argument[-1];ReturnValue;taint",
";MutableCollection;true;withContiguousMutableStorageIfAvailable(_:);;;Argument[-1];Argument[0].Parameter[0].CollectionElement;taint",
";MutableCollection;true;withContiguousMutableStorageIfAvailable(_:);;;Argument[-1].ArrayElement;Argument[0].Parameter[0].CollectionElement;value",
";MutableCollection;true;withContiguousMutableStorageIfAvailable(_:);;;Argument[-1].CollectionElement;Argument[0].Parameter[0].CollectionElement;value",
";MutableCollection;true;withContiguousMutableStorageIfAvailable(_:);;;Argument[0].Parameter[0].CollectionElement;Argument[-1].CollectionElement;value",
";MutableCollection;true;withContiguousMutableStorageIfAvailable(_:);;;Argument[0].ReturnValue;ReturnValue.OptionalSome;value",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ private class SequenceSummaries extends SummaryModelCsv {
";Sequence;true;joined(separator:);;;Argument[-1..0];ReturnValue;taint",
";Sequence;true;first(where:);;;Argument[-1];ReturnValue;taint",
";Sequence;true;withContiguousStorageIfAvailable(_:);;;Argument[-1];Argument[0].Parameter[0].CollectionElement;taint",
";Sequence;true;withContiguousStorageIfAvailable(_:);;;Argument[-1].ArrayElement;Argument[0].Parameter[0].CollectionElement;value",
";Sequence;true;withContiguousStorageIfAvailable(_:);;;Argument[-1].CollectionElement;Argument[0].Parameter[0].CollectionElement;value",
";Sequence;true;withContiguousStorageIfAvailable(_:);;;Argument[0].ReturnValue;ReturnValue.OptionalSome;value",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private class SetSummaries extends SummaryModelCsv {
";Set;true;insert(_:);;;Argument[-1].CollectionElement;ReturnValue.TupleElement[1];value",
";Set;true;insert(_:);;;Argument[0];Argument[-1].CollectionElement;value",
";Set;true;insert(_:);;;Argument[0];ReturnValue.TupleElement[1];value",
";Set;true;init(_:);;;Argument[0].ArrayElement;ReturnValue.CollectionElement;value"
";Set;true;init(_:);;;Argument[0].CollectionElement;ReturnValue.CollectionElement;value"
]
}
}
23 changes: 8 additions & 15 deletions swift/ql/lib/codeql/swift/frameworks/StandardLibrary/String.qll
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ private class StringSummaries extends SummaryModelCsv {
row =
[
";StringProtocol;true;init(cString:);;;Argument[0];ReturnValue;taint",
";StringProtocol;true;init(cString:);;;Argument[0].ArrayElement;ReturnValue;taint",
";StringProtocol;true;init(cString:);;;Argument[0].CollectionElement;ReturnValue;taint",
";StringProtocol;true;init(decoding:as:);;;Argument[0];ReturnValue;taint",
";StringProtocol;true;init(decodingCString:as:);;;Argument[0].OptionalSome.CollectionElement;ReturnValue.OptionalSome.TupleElement[0];taint",
Expand All @@ -46,12 +45,12 @@ private class StringSummaries extends SummaryModelCsv {
";StringProtocol;true;cString(using:);;;Argument[-1];ReturnValue;taint",
";StringProtocol;true;capitalized(with:);;;Argument[-1];ReturnValue;taint",
";StringProtocol;true;completePath(into:caseSensitive:matchesInto:filterTypes:);;;Argument[-1];Argument[0].OptionalSome.CollectionElement;taint",
";StringProtocol;true;completePath(into:caseSensitive:matchesInto:filterTypes:);;;Argument[-1];Argument[2].OptionalSome.CollectionElement.ArrayElement;taint",
";StringProtocol;true;completePath(into:caseSensitive:matchesInto:filterTypes:);;;Argument[-1];Argument[2].OptionalSome.CollectionElement.CollectionElement;taint",
";StringProtocol;true;components(separatedBy:);;;Argument[-1];ReturnValue;taint",
";StringProtocol;true;data(using:allowLossyConversion:);;;Argument[-1];ReturnValue;taint",
";StringProtocol;true;folding(options:locale:);;;Argument[-1];ReturnValue;taint",
";StringProtocol;true;getBytes(_:maxLength:usedLength:encoding:options:range:remaining:);;;Argument[-1];Argument[0].ArrayElement;taint",
";StringProtocol;true;getCString(_:maxLength:encoding:);;;Argument[-1];Argument[0].ArrayElement;taint",
";StringProtocol;true;getBytes(_:maxLength:usedLength:encoding:options:range:remaining:);;;Argument[-1];Argument[0].CollectionElement;taint",
";StringProtocol;true;getCString(_:maxLength:encoding:);;;Argument[-1];Argument[0].CollectionElement;taint",
";StringProtocol;true;lowercased();;;Argument[-1];ReturnValue;taint",
";StringProtocol;true;lowercased(with:);;;Argument[-1];ReturnValue;taint",
";StringProtocol;true;padding(toLength:withPad:startingAt:);;;Argument[-1];ReturnValue;taint",
Expand All @@ -74,20 +73,18 @@ private class StringSummaries extends SummaryModelCsv {
";String;true;init(repeating:count:);;;Argument[0];ReturnValue;taint",
";String;true;init(data:encoding:);;;Argument[0];ReturnValue.OptionalSome;taint",
";String;true;init(validatingUTF8:);;;Argument[0];ReturnValue.OptionalSome;taint",
";String;true;init(validatingUTF8:);;;Argument[0].ArrayElement;ReturnValue.OptionalSome;taint",
";String;true;init(validatingUTF8:);;;Argument[0].CollectionElement;ReturnValue.OptionalSome;taint",
";String;true;init(utf16CodeUnits:count:);;;Argument[0].CollectionElement;ReturnValue;taint",
";String;true;init(utf16CodeUnitsNoCopy:count:freeWhenDone:);;;Argument[0].CollectionElement;ReturnValue;taint",
";String;true;init(format:_:);;;Argument[0];ReturnValue;taint",
";String;true;init(format:_:);;;Argument[1].ArrayElement;ReturnValue;taint",
";String;true;init(format:_:);;;Argument[1].CollectionElement;ReturnValue;taint",
";String;true;init(format:arguments:);;;Argument[0];ReturnValue;taint",
";String;true;init(format:arguments:);;;Argument[1].ArrayElement;ReturnValue;taint",
";String;true;init(format:arguments:);;;Argument[1].CollectionElement;ReturnValue;taint",
";String;true;init(format:locale:_:);;;Argument[0];ReturnValue;taint",
";String;true;init(format:locale:_:);;;Argument[2].ArrayElement;ReturnValue;taint",
";String;true;init(format:locale:_:);;;Argument[2].CollectionElement;ReturnValue;taint",
";String;true;init(format:locale:arguments:);;;Argument[0];ReturnValue;taint",
";String;true;init(format:locale:arguments:);;;Argument[2].ArrayElement;ReturnValue;taint",
";String;true;init(format:locale:arguments:);;;Argument[2].CollectionElement;ReturnValue;taint",
";String;true;init(_:radix:uppercase:);;;Argument[0];ReturnValue;taint",
";String;true;init(bytes:encoding:);;;Argument[0].ArrayElement;ReturnValue.OptionalSome;taint",
";String;true;init(bytes:encoding:);;;Argument[0].CollectionElement;ReturnValue.OptionalSome;taint",
";String;true;init(bytesNoCopy:length:encoding:freeWhenDone:);;;Argument[0].CollectionElement;ReturnValue.OptionalSome;taint",
";String;true;init(describing:);;;Argument[0];ReturnValue;taint",
Expand All @@ -104,20 +101,16 @@ private class StringSummaries extends SummaryModelCsv {
";String;true;init(unicodeScalarLiteral:);;;Argument[0];ReturnValue;taint",
";String;true;init(extendedGraphemeClusterLiteral:);;;Argument[0];ReturnValue;taint",
";String;true;init(cString:encoding:);;;Argument[0];ReturnValue.OptionalSome;taint",
";String;true;init(cString:encoding:);;;Argument[0].ArrayElement;ReturnValue.OptionalSome;taint",
";String;true;init(cString:encoding:);;;Argument[0].CollectionElement;ReturnValue.OptionalSome;taint",
";String;true;init(platformString:);;;Argument[0];ReturnValue;taint",
";String;true;init(platformString:);;;Argument[0].ArrayElement;ReturnValue;taint",
";String;true;init(platformString:);;;Argument[0].CollectionElement;ReturnValue;taint",
";String;true;init(utf8String:);;;Argument[0];ReturnValue.OptionalSome;taint",
";String;true;init(utf8String:);;;Argument[0].ArrayElement;ReturnValue.OptionalSome;taint",
";String;true;init(utf8String:);;;Argument[0].CollectionElement;ReturnValue.OptionalSome;taint",
";String;true;init(validating:);;;Argument[0];ReturnValue.OptionalSome;taint",
";String;true;init(validatingPlatformString:);;;Argument[0];ReturnValue.OptionalSome;taint",
";String;true;init(validatingPlatformString:);;;Argument[0].ArrayElement;ReturnValue.OptionalSome;taint",
";String;true;init(validatingPlatformString:);;;Argument[0].CollectionElement;ReturnValue.OptionalSome;taint",
";String;true;localizedStringWithFormat(_:_:);;;Argument[0];ReturnValue;taint",
";String;true;localizedStringWithFormat(_:_:);;;Argument[1].ArrayContent;ReturnValue;taint",
";String;true;localizedStringWithFormat(_:_:);;;Argument[1].CollectionElement;ReturnValue;taint",
";String;true;write(_:);;;Argument[0];Argument[-1];taint",
";String;true;write(to:);;;Argument[-1];Argument[0];taint",
";String;true;insert(contentsOf:at:);;;Argument[0];Argument[-1];taint",
Expand Down
5 changes: 1 addition & 4 deletions swift/ql/lib/codeql/swift/security/UnsafeJsEvalQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ module UnsafeJsEvalConfig implements DataFlow::ConfigSig {
or
isAdditionalFlowStep(node, _)
) and
(
c.getAReadContent() instanceof DataFlow::Content::ArrayContent or
c.getAReadContent() instanceof DataFlow::Content::CollectionContent
)
c.getAReadContent() instanceof DataFlow::Content::CollectionContent
}
}

Expand Down
Loading