Skip to content

Commit 16ec29e

Browse files
committed
Swift: Test taint throguh some NSObject methods.
1 parent 85a0fd9 commit 16ec29e

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

swift/ql/test/library-tests/dataflow/taint/nsstring.swift

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,22 @@
44
typealias unichar = UInt16
55

66
class NSObject {
7+
func copy() -> Any { return 0 }
8+
func mutableCopy() -> Any { return 0 }
79
}
810

9-
class NSString : NSObject {
11+
struct NSZone {
12+
}
13+
14+
protocol NSCopying {
15+
func copy(with zone: NSZone?) -> Any
16+
}
17+
18+
protocol NSMutableCopying {
19+
func mutableCopy(with zone: NSZone?) -> Any
20+
}
21+
22+
class NSString : NSObject, NSCopying, NSMutableCopying {
1023
struct EncodingConversionOptions : OptionSet {
1124
let rawValue: Int
1225
}
@@ -37,6 +50,9 @@ class NSString : NSObject {
3750
convenience init?(contentsOfFile path: String) { self.init(string: "") }
3851
convenience init?(contentsOf url: URL) { self.init(string: "") }
3952

53+
func copy(with zone: NSZone? = nil) -> Any { return 0 }
54+
func mutableCopy(with zone: NSZone? = nil) -> Any { return 0 }
55+
4056
class func localizedStringWithFormat(_ format: NSString, _ args: CVarArg) -> Self { return (nil as Self?)! }
4157
class func path(withComponents components: [String]) -> String { return "" }
4258
class func string(withCString bytes: UnsafePointer<CChar>) -> Any? { return nil }
@@ -322,4 +338,13 @@ func taintThroughInterpolatedStrings() {
322338
sink(arg: outBuffer) // $ MISSING: tainted=
323339
sink(arg: outBuffer.pointee) // $ MISSING: tainted=
324340
}
341+
342+
// `NSObject` methods
343+
344+
var str20 = sourceNSString()
345+
346+
sink(arg: str20.copy()) // $ MISSING: tainted=
347+
sink(arg: str20.mutableCopy()) // $ MISSING: tainted=
348+
sink(arg: str20.copy(with: nil)) // $ MISSING: tainted=
349+
sink(arg: str20.mutableCopy(with: nil)) // $ MISSING: tainted=
325350
}

0 commit comments

Comments
 (0)