Skip to content

Commit 49d1556

Browse files
committed
Swift: Model update(repeating:), to support the tests.
1 parent 315cb32 commit 49d1556

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import swift
7+
private import codeql.swift.dataflow.ExternalFlow
78

89
/**
910
* A Swift unsafe typed pointer type such as `UnsafePointer`,
@@ -57,3 +58,12 @@ class CVaListPointerType extends NominalType {
5758
class ManagedBufferPointerType extends BoundGenericType {
5859
ManagedBufferPointerType() { this.getName().matches("ManagedBufferPointer<%") }
5960
}
61+
62+
/**
63+
* A model for `UnsafePointer` and related Swift class members that permit taint flow.
64+
*/
65+
private class PointerSummaries extends SummaryModelCsv {
66+
override predicate row(string row) {
67+
row = ";UnsafeMutableBufferPointer;true;update(repeating:);;;Argument[0];Argument[-1];taint"
68+
}
69+
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ func taintThroughMutablePointer() {
4545
let return1 = myArray1.withUnsafeMutableBufferPointer({
4646
buffer in
4747
buffer.update(repeating: source())
48-
sink(arg: buffer)
49-
sink(arg: buffer[0]) // $ MISSING: tainted=47
48+
sink(arg: buffer) // $ tainted=47
49+
sink(arg: buffer[0]) // $ tainted=47
5050
sink(arg: buffer.baseAddress!.pointee) // $ MISSING: tainted=47
5151
return source()
5252
})
@@ -81,8 +81,8 @@ func taintThroughMutablePointer() {
8181
let return3 = myArray3.withContiguousMutableStorageIfAvailable({
8282
ptr in
8383
ptr.update(repeating: source())
84-
sink(arg: ptr)
85-
sink(arg: ptr[0]) // $ MISSING: tainted=83
84+
sink(arg: ptr) // $ tainted=83
85+
sink(arg: ptr[0]) // $ tainted=83
8686
return source()
8787
})
8888
sink(arg: return3!) // $ MISSING: tainted=83
@@ -129,8 +129,8 @@ func taintThroughMutablePointer() {
129129
let return6 = myMutableBuffer.withContiguousMutableStorageIfAvailable({
130130
ptr in
131131
ptr.update(repeating: source2())
132-
sink(arg: ptr)
133-
sink(arg: ptr[0]) // $ MISSING: tainted=131
132+
sink(arg: ptr) // $ tainted=131
133+
sink(arg: ptr[0]) // $ tainted=131
134134
return source()
135135
})
136136
sink(arg: return6!) // $ MISSING: tainted=134

0 commit comments

Comments
 (0)