Skip to content

Commit c1f19dd

Browse files
committed
Add stub so that tests work on Linux
1 parent b203a9e commit c1f19dd

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

swift/ql/test/query-tests/Security/CWE-312/cleartextLoggingTest.swift

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
func NSLog(_ format: String, _ args: CVarArg...) {}
44
func NSLogv(_ format: String, _ args: CVaListPointer) {}
5+
func getVaList(_ args: [CVarArg]) -> CVaListPointer { return CVaListPointer(_fromUnsafeMutablePointer: UnsafeMutablePointer(bitPattern: 0)!) }
56

67
struct OSLogType : RawRepresentable {
78
static let `default` = OSLogType(rawValue: 0)
@@ -83,42 +84,42 @@ struct Logger {
8384
// --- tests ---
8485

8586
func test1(password: String, passwordHash : String) {
86-
print(password) // $ MISSING: hasCleartextLogging=86
87-
print(password, separator: "") // $ MISSING: $ hasCleartextLogging=97
88-
print("", separator: password) // $ hasCleartextLogging=88
89-
print(password, separator: "", terminator: "") // $ MISSING: hasCleartextLogging=89
90-
print("", separator: password, terminator: "") // $ hasCleartextLogging=90
91-
print("", separator: "", terminator: password) // $ hasCleartextLogging=91
92-
93-
NSLog(password) // $ hasCleartextLogging=93
94-
NSLog("%@", password as! CVarArg) // $ MISSING: hasCleartextLogging=94
95-
NSLog("%@ %@", "" as! CVarArg, password as! CVarArg) // $ MISSING: hasCleartextLogging=95
96-
NSLog("\(password)") // $ hasCleartextLogging=96
97-
NSLogv("%@", getVaList([password as! CVarArg])) // $ MISSING: hasCleartextLogging=97
98-
NSLogv("%@ %@", getVaList(["" as! CVarArg, password as! CVarArg])) // $ MISSING: hasCleartextLogging=98
87+
print(password) // $ MISSING: hasCleartextLogging=87
88+
print(password, separator: "") // $ MISSING: $ hasCleartextLogging=88
89+
print("", separator: password) // $ hasCleartextLogging=89
90+
print(password, separator: "", terminator: "") // $ MISSING: hasCleartextLogging=90
91+
print("", separator: password, terminator: "") // $ hasCleartextLogging=91
92+
print("", separator: "", terminator: password) // $ hasCleartextLogging=92
93+
94+
NSLog(password) // $ hasCleartextLogging=94
95+
NSLog("%@", password as! CVarArg) // $ MISSING: hasCleartextLogging=95
96+
NSLog("%@ %@", "" as! CVarArg, password as! CVarArg) // $ MISSING: hasCleartextLogging=96
97+
NSLog("\(password)") // $ hasCleartextLogging=97
98+
NSLogv("%@", getVaList([password as! CVarArg])) // $ MISSING: hasCleartextLogging=98
99+
NSLogv("%@ %@", getVaList(["" as! CVarArg, password as! CVarArg])) // $ MISSING: hasCleartextLogging=99
99100

100101
let bankAccount: Int = 0
101102
let log = Logger()
102103
// These MISSING test cases will be fixed when we properly generate the CFG around autoclosures.
103104
log.log("\(password)") // Safe
104105
log.log("\(password, privacy: .auto)") // Safe
105106
log.log("\(password, privacy: .private)") // Safe
106-
log.log("\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=106
107+
log.log("\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=107
107108
log.log("\(password, privacy: .sensitive)") // Safe
108-
log.log("\(bankAccount)") // $ MISSING: hasCleartextLogging=108
109-
log.log("\(bankAccount, privacy: .auto)") // $ MISSING: hasCleartextLogging=109
109+
log.log("\(bankAccount)") // $ MISSING: hasCleartextLogging=109
110+
log.log("\(bankAccount, privacy: .auto)") // $ MISSING: hasCleartextLogging=110
110111
log.log("\(bankAccount, privacy: .private)") // Safe
111-
log.log("\(bankAccount, privacy: .public)") // $ MISSING: hasCleartextLogging=111
112+
log.log("\(bankAccount, privacy: .public)") // $ MISSING: hasCleartextLogging=112
112113
log.log("\(bankAccount, privacy: .sensitive)") // Safe
113-
log.log(level: .default, "\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=113
114-
log.trace("\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=114
115-
log.debug("\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=115
116-
log.info("\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=116
117-
log.notice("\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=117
118-
log.warning("\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=118
119-
log.error("\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=119
120-
log.critical("\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=120
121-
log.fault("\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=121
114+
log.log(level: .default, "\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=114
115+
log.trace("\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=115
116+
log.debug("\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=116
117+
log.info("\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=117
118+
log.notice("\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=118
119+
log.warning("\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=119
120+
log.error("\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=120
121+
log.critical("\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=121
122+
log.fault("\(password, privacy: .public)") // $ MISSING: hasCleartextLogging=122
122123
}
123124
/*
124125
class MyClass {

0 commit comments

Comments
 (0)