@@ -4,6 +4,7 @@ class NSObject { }
4
4
5
5
func NSLog( _ format: String , _ args: CVarArg ... ) { }
6
6
func NSLogv( _ format: String , _ args: CVaListPointer ) { }
7
+
7
8
func getVaList( _ args: [ CVarArg ] ) -> CVaListPointer { return CVaListPointer ( _fromUnsafeMutablePointer: UnsafeMutablePointer ( bitPattern: 0 ) !) }
8
9
9
10
struct OSLogType : RawRepresentable {
@@ -92,34 +93,88 @@ extension String : CVarArg {
92
93
public var _cVarArgEncoding : [ Int ] { get { return [ ] } }
93
94
}
94
95
96
+ struct NSExceptionName {
97
+ init ( _ rawValue: String ) { }
98
+ }
99
+
100
+ class NSException : NSObject
101
+ {
102
+ init ( name aName: NSExceptionName , reason aReason: String ? , userInfo aUserInfo: [ AnyHashable : Any ] ? = nil ) { }
103
+ class func raise( _ name: NSExceptionName , format: String , arguments argList: CVaListPointer ) { }
104
+ func raise( ) { }
105
+ }
106
+
107
+ class NSString : NSObject {
108
+ convenience init ( string aString: String ) { self . init ( ) }
109
+ }
110
+
95
111
// from ObjC API; slightly simplified.
96
112
func os_log( _ message: StaticString ,
97
113
dso: UnsafeRawPointer ? = nil ,
98
114
log: OSLog = . default,
99
115
type: OSLogType = . default,
100
116
_ args: CVarArg ... ) { }
101
117
118
+ // imported from C
119
+ typealias FILE = Int32 // this is a simplification
120
+ typealias wchar_t = Int32
121
+ typealias locale_t = OpaquePointer
122
+ func dprintf( _ fd: Int , _ format: UnsafePointer < Int8 > , _ args: CVarArg ... ) -> Int32 { return 0 }
123
+ func vprintf( _ format: UnsafePointer < CChar > , _ arg: CVaListPointer ) -> Int32 { return 0 }
124
+ func vfprintf( _ file: UnsafeMutablePointer < FILE > ? , _ format: UnsafePointer < CChar > ? , _ arg: CVaListPointer ) -> Int32 { return 0 }
125
+ func vasprintf_l( _ ret: UnsafeMutablePointer < UnsafeMutablePointer < CChar > ? > ? , _ loc: locale_t ? , _ format: UnsafePointer < CChar > ? , _ ap: CVaListPointer ) -> Int32 { return 0 }
126
+
127
+ // custom
128
+ func log( message: String ) { }
129
+ func logging( message: String ) { }
130
+ func logfile( file: Int , message: String ) { }
131
+ func logMessage( _ msg: NSString ) { }
132
+ func logInfo( _ infoMsg: String ) { }
133
+ func logError( errorMsg str: String ) { }
134
+ func harmless( _ str: String ) { } // safe
135
+ func logarithm( _ val: Float ) { } // safe
136
+ func doLogin( login: String ) { } // safe
137
+
138
+ // custom
139
+ class LogFile {
140
+ func log( _ str: String ) { }
141
+ func trace( _ message: String ? ) { }
142
+ func debug( _ message: String ) { }
143
+ func info( _ info: NSString ) { }
144
+ func notice( _ notice: String ) { }
145
+ func warning( _ warningMessage: String ) { }
146
+ func error( _ msg: String ) { }
147
+ func critical( _ criticalMsg: String ) { }
148
+ func fatal( _ str: String ) { }
149
+ }
150
+
151
+ // custom
152
+ class Logic {
153
+ func addInt( _ val: Int ) { } // safe
154
+ func addString( _ str: String ) { } // safe
155
+ }
156
+
102
157
// --- tests ---
103
158
104
159
func test1( password: String , passwordHash : String , passphrase: String , pass_phrase: String ) {
105
- print ( password) // $ hasCleartextLogging=105
106
- print ( password, separator: " " ) // $ $ hasCleartextLogging=106
107
- print ( " " , separator: password) // $ hasCleartextLogging=107
108
- print ( password, separator: " " , terminator: " " ) // $ hasCleartextLogging=108
109
- print ( " " , separator: password, terminator: " " ) // $ hasCleartextLogging=109
110
- print ( " " , separator: " " , terminator: password) // $ hasCleartextLogging=110
160
+ print ( password) // $ hasCleartextLogging=160
161
+ print ( password, separator: " " ) // $ $ hasCleartextLogging=161
162
+ print ( " " , separator: password) // $ hasCleartextLogging=162
163
+ print ( password, separator: " " , terminator: " " ) // $ hasCleartextLogging=163
164
+ print ( " " , separator: password, terminator: " " ) // $ hasCleartextLogging=164
165
+ print ( " " , separator: " " , terminator: password) // $ hasCleartextLogging=165
111
166
print ( passwordHash) // safe
112
167
113
- debugPrint ( password) // $ hasCleartextLogging=113
168
+ debugPrint ( password) // $ hasCleartextLogging=168
114
169
115
- dump ( password) // $ hasCleartextLogging=115
170
+ dump ( password) // $ hasCleartextLogging=170
116
171
117
- NSLog ( password) // $ hasCleartextLogging=117
118
- NSLog ( " %@ " , password) // $ hasCleartextLogging=118
119
- NSLog ( " %@ %@ " , " " , password) // $ hasCleartextLogging=119
120
- NSLog ( " \( password) " ) // $ hasCleartextLogging=120
121
- NSLogv ( " %@ " , getVaList ( [ password] ) ) // $ hasCleartextLogging=121
122
- NSLogv ( " %@ %@ " , getVaList ( [ " " , password] ) ) // $ hasCleartextLogging=122
172
+ NSLog ( password) // $ hasCleartextLogging=172
173
+ NSLog ( " %@ " , password) // $ hasCleartextLogging=173
174
+ NSLog ( " %@ %@ " , " " , password) // $ hasCleartextLogging=174
175
+ NSLog ( " \( password) " ) // $ hasCleartextLogging=175
176
+ NSLogv ( " %@ " , getVaList ( [ password] ) ) // $ hasCleartextLogging=176
177
+ NSLogv ( " %@ %@ " , getVaList ( [ " " , password] ) ) // $ hasCleartextLogging=177
123
178
NSLog ( passwordHash) // safe
124
179
NSLogv ( " %@ " , getVaList ( [ passwordHash] ) ) // safe
125
180
@@ -129,39 +184,38 @@ func test1(password: String, passwordHash : String, passphrase: String, pass_phr
129
184
log. log ( " \( password) " ) // safe
130
185
log. log ( " \( password, privacy: . auto) " ) // safe
131
186
log. log ( " \( password, privacy: . private) " ) // safe
132
- log. log ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=132
187
+ log. log ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=187
133
188
log. log ( " \( passwordHash, privacy: . public) " ) // safe
134
189
log. log ( " \( password, privacy: . sensitive) " ) // safe
135
- log. log ( " \( bankAccount) " ) // $ MISSING: hasCleartextLogging=135
136
- log. log ( " \( bankAccount, privacy: . auto) " ) // $ MISSING: hasCleartextLogging=136
190
+ log. log ( " \( bankAccount) " ) // $ MISSING: hasCleartextLogging=190
191
+ log. log ( " \( bankAccount, privacy: . auto) " ) // $ MISSING: hasCleartextLogging=191
137
192
log. log ( " \( bankAccount, privacy: . private) " ) // safe
138
- log. log ( " \( bankAccount, privacy: . public) " ) // $ MISSING: hasCleartextLogging=138
193
+ log. log ( " \( bankAccount, privacy: . public) " ) // $ MISSING: hasCleartextLogging=193
139
194
log. log ( " \( bankAccount, privacy: . sensitive) " ) // safe
140
- log. log ( level: . default, " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=140
141
- log. trace ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=141
195
+ log. log ( level: . default, " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=195
196
+ log. trace ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=196
142
197
log. trace ( " \( passwordHash, privacy: . public) " ) // safe
143
- log. debug ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=143
198
+ log. debug ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=198
144
199
log. debug ( " \( passwordHash, privacy: . public) " ) // safe
145
- log. info ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=145
200
+ log. info ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=200
146
201
log. info ( " \( passwordHash, privacy: . public) " ) // safe
147
- log. notice ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=147
202
+ log. notice ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=202
148
203
log. notice ( " \( passwordHash, privacy: . public) " ) // safe
149
- log. warning ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=149
204
+ log. warning ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=204
150
205
log. warning ( " \( passwordHash, privacy: . public) " ) // safe
151
- log. error ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=151
206
+ log. error ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=206
152
207
log. error ( " \( passwordHash, privacy: . public) " ) // safe
153
- log. critical ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=153
208
+ log. critical ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=208
154
209
log. critical ( " \( passwordHash, privacy: . public) " ) // safe
155
- log. fault ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=155
210
+ log. fault ( " \( password, privacy: . public) " ) // $ MISSING: hasCleartextLogging=210
156
211
log. fault ( " \( passwordHash, privacy: . public) " ) // safe
157
212
158
- NSLog ( passphrase) // $ hasCleartextLogging=158
159
- NSLog ( pass_phrase) // $ hasCleartextLogging=159
213
+ NSLog ( passphrase) // $ hasCleartextLogging=213
214
+ NSLog ( pass_phrase) // $ hasCleartextLogging=214
160
215
161
216
os_log ( " %@ " , log: . default, type: . default, " " ) // safe
162
- os_log ( " %@ " , log: . default, type: . default, password) // $ hasCleartextLogging=162
163
- os_log ( " %@ %@ %@ " , log: . default, type: . default, " " , " " , password) // $ hasCleartextLogging=163
164
-
217
+ os_log ( " %@ " , log: . default, type: . default, password) // $ hasCleartextLogging=217
218
+ os_log ( " %@ %@ %@ " , log: . default, type: . default, " " , " " , password) // $ hasCleartextLogging=218
165
219
}
166
220
167
221
class MyClass {
@@ -175,16 +229,16 @@ func doSomething(password: String) { }
175
229
func test3( x: String ) {
176
230
// alternative evidence of sensitivity...
177
231
178
- NSLog ( x) // $ MISSING: hasCleartextLogging=179
232
+ NSLog ( x) // $ MISSING: hasCleartextLogging=233
179
233
doSomething ( password: x) ;
180
- NSLog ( x) // $ hasCleartextLogging=179
234
+ NSLog ( x) // $ hasCleartextLogging=233
181
235
182
236
let y = getPassword ( ) ;
183
- NSLog ( y) // $ hasCleartextLogging=182
237
+ NSLog ( y) // $ hasCleartextLogging=236
184
238
185
239
let z = MyClass ( )
186
240
NSLog ( z. harmless) // safe
187
- NSLog ( z. password) // $ hasCleartextLogging=187
241
+ NSLog ( z. password) // $ hasCleartextLogging=241
188
242
}
189
243
190
244
struct MyOuter {
@@ -199,7 +253,7 @@ struct MyOuter {
199
253
func test3( mo : MyOuter ) {
200
254
// struct members...
201
255
202
- NSLog ( mo. password. value) // $ hasCleartextLogging=202
256
+ NSLog ( mo. password. value) // $ hasCleartextLogging=256
203
257
NSLog ( mo. harmless. value) // safe
204
258
}
205
259
@@ -223,39 +277,39 @@ func test4(harmless: String, password: String) {
223
277
print ( myString1) // safe
224
278
225
279
print ( password, to: & myString2)
226
- print ( myString2) // $ hasCleartextLogging=225
280
+ print ( myString2) // $ hasCleartextLogging=279
227
281
228
282
print ( " log: " + password, to: & myString3)
229
- print ( myString3) // $ hasCleartextLogging=228
283
+ print ( myString3) // $ hasCleartextLogging=282
230
284
231
285
debugPrint ( harmless, to: & myString4)
232
286
debugPrint ( myString4) // safe
233
287
234
288
debugPrint ( password, to: & myString5)
235
- debugPrint ( myString5) // $ hasCleartextLogging=234
289
+ debugPrint ( myString5) // $ hasCleartextLogging=288
236
290
237
291
dump ( harmless, to: & myString6)
238
292
dump ( myString6) // safe
239
293
240
294
dump ( password, to: & myString7)
241
- dump ( myString7) // $ hasCleartextLogging=240
295
+ dump ( myString7) // $ hasCleartextLogging=294
242
296
243
297
myString8. write ( harmless)
244
298
print ( myString8)
245
299
246
300
myString9. write ( password)
247
- print ( myString9) // $ hasCleartextLogging=246
301
+ print ( myString9) // $ hasCleartextLogging=300
248
302
249
303
myString10. write ( harmless)
250
304
myString10. write ( password)
251
305
myString10. write ( harmless)
252
- print ( myString10) // $ hasCleartextLogging=250
306
+ print ( myString10) // $ hasCleartextLogging=304
253
307
254
308
harmless. write ( to: & myString11)
255
309
print ( myString11)
256
310
257
311
password. write ( to: & myString12)
258
- print ( myString12) // $ hasCleartextLogging=257
312
+ print ( myString12) // $ hasCleartextLogging=311
259
313
260
314
print ( password, to: & myString13) // $ safe - only printed to another string
261
315
debugPrint ( password, to: & myString13) // $ safe - only printed to another string
@@ -270,14 +324,14 @@ func test5(password: String, caseNum: Int) {
270
324
271
325
switch caseNum {
272
326
case 0 :
273
- assert ( false , password) // $ MISSING: hasCleartextLogging=273
327
+ assert ( false , password) // $ MISSING: hasCleartextLogging=327
274
328
case 1 :
275
- assertionFailure ( password) // $ MISSING: hasCleartextLogging=275
329
+ assertionFailure ( password) // $ MISSING: hasCleartextLogging=329
276
330
case 2 :
277
- precondition ( false , password) // $ MISSING: hasCleartextLogging=277
331
+ precondition ( false , password) // $ MISSING: hasCleartextLogging=331
278
332
case 3 :
279
- preconditionFailure ( password) // $ MISSING: hasCleartextLogging=279
333
+ preconditionFailure ( password) // $ MISSING: hasCleartextLogging=333
280
334
default :
281
- fatalError ( password) // $ MISSING: hasCleartextLogging=281
335
+ fatalError ( password) // $ MISSING: hasCleartextLogging=335
282
336
}
283
337
}
0 commit comments