Skip to content

Commit a3ef9f0

Browse files
Fix UB in defaults loading (#5456)
* Fix UB in defaults loading * Add changelog entry * One more isDirectory Co-authored-by: samedson <[email protected]>
1 parent 3ad227a commit a3ef9f0

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Crashlytics/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Unreleased
22

33
- [fixed] Fixed unchecked `malloc`s in Crashlytics (#5428).
4+
- [fixed] Fixed an instance of undefined behavior when loading files from disk (#5454).
45

56
# v4.0.0
67

Crashlytics/Crashlytics/FIRCLSUserDefaults/FIRCLSUserDefaults.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ - (void)synchronize {
235235
NSDictionary *state = [self dictionaryRepresentation];
236236
dispatch_sync(self.synchronizationQueue, ^{
237237
#if CLS_TARGET_CAN_WRITE_TO_DISK
238-
BOOL isDirectory;
238+
BOOL isDirectory = NO;
239239
BOOL pathExists = [[NSFileManager defaultManager] fileExistsAtPath:[self->_directoryURL path]
240240
isDirectory:&isDirectory];
241241

@@ -280,7 +280,7 @@ - (NSDictionary *)loadDefaults {
280280
__block NSDictionary *state = nil;
281281
dispatch_sync(self.synchronizationQueue, ^{
282282
#if CLS_TARGET_CAN_WRITE_TO_DISK
283-
BOOL isDirectory;
283+
BOOL isDirectory = NO;
284284
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[self->_fileURL path]
285285
isDirectory:&isDirectory];
286286

@@ -289,7 +289,7 @@ - (NSDictionary *)loadDefaults {
289289
if (nil == state) {
290290
FIRCLSErrorLog(@"Failed to read existing UserDefaults file");
291291
}
292-
} else if (!fileExists && !isDirectory) {
292+
} else if (!fileExists) {
293293
// No file found. This is expected on first launch.
294294
} else if (fileExists && isDirectory) {
295295
FIRCLSErrorLog(@"Found directory where file expected. Removing conflicting directory");

0 commit comments

Comments
 (0)