Skip to content

Commit 1e5b904

Browse files
committed
Swift: Add test cases for mutating pointers inside containers.
1 parent 56b6441 commit 1e5b904

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,31 @@ func testMutatingMyPointerInCall(ptr: MyPointer) {
9999
sink(arg: ptr.pointee) // $ MISSING: tainted=87
100100
sink(arg: ptr)
101101
}
102+
103+
// ---
104+
105+
struct MyPointerContainer {
106+
var ptr: UnsafeMutablePointer<String>
107+
}
108+
109+
struct MyGenericPointerContainer<T> {
110+
var ptr: UnsafeMutablePointer<T>
111+
}
112+
113+
func writePointerContainer(mpc: MyPointerContainer) {
114+
mpc.ptr.pointee = sourceString()
115+
sink(arg: mpc.ptr.pointee) // $ tainted=114
116+
}
117+
118+
func writeGenericPointerContainer<T>(mgpc: MyGenericPointerContainer<T>) {
119+
mgpc.ptr.pointee = sourceString() as! T
120+
sink(arg: mgpc.ptr.pointee) // $ tainted=119
121+
}
122+
123+
func testWritingPointerContainersInCalls(mpc: MyPointerContainer, mgpc: MyGenericPointerContainer<Int>) {
124+
writePointerContainer(mpc: mpc)
125+
sink(arg: mpc.ptr.pointee) // $ tainted=114
126+
127+
writeGenericPointerContainer(mgpc: mgpc)
128+
sink(arg: mgpc.ptr.pointee) // $ MISSING: tainted=119
129+
}

0 commit comments

Comments
 (0)