2
0

Fixed potential crashed due to rare nil values at checkpoints.

[FIXED]     Avoid nil values at checkpoints since they will cause crashes.
This commit is contained in:
Maarten Billemont 2013-08-15 19:38:05 -04:00
parent 0a5329fe17
commit 2d8146edbd
7 changed files with 49 additions and 52 deletions

View File

@ -74,7 +74,7 @@ static NSDictionary *keyQuery(MPUserEntity *user) {
- (BOOL)signInAsUser:(MPUserEntity *)user saveInContext:(NSManagedObjectContext *)moc usingMasterPassword:(NSString *)password {
if (password)
NSAssert(![NSThread isMainThread], @"Computing key must not happen from the main thread.");
NSAssert(![NSThread isMainThread], @"Computing key must not happen from the main thread.");
MPKey *tryKey = nil;

View File

@ -105,14 +105,15 @@ PearlAssociatedObjectProperty(NSManagedObjectContext*, MainManagedObjectContext,
#if TARGET_OS_IPHONE
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillTerminateNotification object:[UIApplication sharedApplication]
queue:[NSOperationQueue mainQueue] usingBlock:
^(NSNotification *note) {
[[self mainManagedObjectContext] saveToStore];
}];
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillResignActiveNotification object:[UIApplication sharedApplication]
queue:[NSOperationQueue mainQueue] usingBlock:
^(NSNotification *note) {
[[self mainManagedObjectContext] saveToStore];
}];
^(NSNotification *note) {
[[self mainManagedObjectContext] saveToStore];
}];
[[NSNotificationCenter defaultCenter]
addObserverForName:UIApplicationWillResignActiveNotification object:[UIApplication sharedApplication]
queue:[NSOperationQueue mainQueue] usingBlock:
^(NSNotification *note) {
[[self mainManagedObjectContext] saveToStore];
}];
#else
[[NSNotificationCenter defaultCenter] addObserverForName:NSApplicationWillTerminateNotification object:NSApp
queue:[NSOperationQueue mainQueue] usingBlock:
@ -374,7 +375,7 @@ PearlAssociatedObjectProperty(NSManagedObjectContext*, MainManagedObjectContext,
err(@"[StoreManager] ERROR: cause=%d, context=%@, error=%@", cause, context, error);
MPCheckpoint( MPCheckpointMPErrorUbiquity, @{
@"cause" : @(cause),
@"error.domain" : error.domain,
@"error.domain" : NilToNSNull(error.domain),
@"error.code" : @(error.code)
} );
}
@ -413,7 +414,8 @@ PearlAssociatedObjectProperty(NSManagedObjectContext*, MainManagedObjectContext,
NSManagedObjectID *elementOID = [element objectID];
dispatch_async( dispatch_get_main_queue(), ^{
completion( (MPElementEntity *)[[MPAppDelegate_Shared managedObjectContextForMainThreadIfReady] objectRegisteredForID:elementOID] );
completion(
(MPElementEntity *)[[MPAppDelegate_Shared managedObjectContextForMainThreadIfReady] objectRegisteredForID:elementOID] );
} );
}];
}

View File

@ -271,7 +271,7 @@ forRowAtIndexPath:(NSIndexPath *)indexPath {
[context saveToStore];
MPCheckpoint( MPCheckpointDeleteElement, @{
@"type" : element.typeName,
@"type" : NilToNSNull(element.typeName),
@"version" : @(element.version)
} );
}];

View File

@ -319,7 +319,7 @@
- (void)setHelpChapter:(NSString *)chapter {
MPCheckpoint( MPCheckpointHelpChapter, @{
@"chapter" : chapter
@"chapter" : NilToNSNull(chapter)
} );
dispatch_async( dispatch_get_main_queue(), ^{
@ -479,7 +479,7 @@
[self showContentTip:@"Copied!" withIcon:nil];
MPCheckpoint( MPCheckpointCopyToPasteboard, @{
@"type" : activeElement.typeName,
@"type" : NilToNSNull(activeElement.typeName),
@"version" : @(activeElement.version),
@"emergency" : @NO
} );
@ -497,7 +497,7 @@
[self showLoginNameTip:@"Copied!"];
MPCheckpoint( MPCheckpointCopyLoginNameToPasteboard, @{
@"type" : activeElement.typeName,
@"type" : NilToNSNull(activeElement.typeName),
@"version" : @(activeElement.version)
} );
}
@ -521,7 +521,7 @@
++activeGeneratedElement.counter;
MPCheckpoint( MPCheckpointIncrementPasswordCounter, @{
@"type" : activeGeneratedElement.typeName,
@"type" : NilToNSNull(activeGeneratedElement.typeName),
@"version" : @(activeGeneratedElement.version),
@"counter" : @(activeGeneratedElement.counter)
} );
@ -553,7 +553,7 @@
((MPElementGeneratedEntity *)activeElement_).counter = 1;
MPCheckpoint( MPCheckpointResetPasswordCounter, @{
@"type" : activeElement_.typeName,
@"type" : NilToNSNull(activeElement_.typeName),
@"version" : @(activeElement_.version)
} );
return YES;
@ -574,7 +574,7 @@
[self.loginNameField becomeFirstResponder];
MPCheckpoint( MPCheckpointEditLoginName, @{
@"type" : activeElement.typeName,
@"type" : NilToNSNull(activeElement.typeName),
@"version" : @(activeElement.version)
} );
}
@ -601,7 +601,7 @@
NSString *oldPassword = [activeElement.content description];
if (!task( activeElement, context ))
return;
activeElement = [self activeElementInContext:context];
NSString *newPassword = [activeElement.content description];
@ -655,7 +655,7 @@
[self.contentField becomeFirstResponder];
MPCheckpoint( MPCheckpointEditPassword, @{
@"type" : activeElement.typeName,
@"type" : NilToNSNull(activeElement.typeName),
@"version" : @(activeElement.version)
} );
}
@ -680,7 +680,7 @@
[activeElement_ migrateExplicitly:YES];
MPCheckpoint( MPCheckpointExplicitMigration, @{
@"type" : activeElement_.typeName,
@"type" : NilToNSNull(activeElement_.typeName),
@"version" : @(activeElement_.version)
} );
return YES;
@ -831,11 +831,11 @@
} );
}
}];
MPCheckpoint( MPCheckpointUseType, @{
@"type" : element.typeName,
@"version" : @(element.version)
} );
@"type" : NilToNSNull(element.typeName),
@"version" : @(element.version)
} );
}
[self.searchDisplayController setActive:NO animated:YES];

View File

@ -6,7 +6,6 @@
// Copyright (c) 2012 Lyndir. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import "MPPreferencesViewController.h"
#import "MPiOSAppDelegate.h"
#import "MPAppDelegate_Key.h"
@ -99,7 +98,7 @@
if (motion == UIEventSubtypeMotionShake) {
MPCheckpoint( MPCheckpointLogs, @{
@"trace": [MPiOSConfig get].traceMode
@"trace" : [MPiOSConfig get].traceMode
} );
[self performSegueWithIdentifier:@"MP_Logs" sender:self];
}

View File

@ -6,16 +6,13 @@
// Copyright (c) 2012 Lyndir. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import <Social/Social.h>
#import <CoreGraphics/CoreGraphics.h>
#import "MPUnlockViewController.h"
#import "MPiOSAppDelegate.h"
#import "MPAppDelegate_Key.h"
#import "MPAppDelegate_Store.h"
@interface MPUnlockViewController()
@property(strong, nonatomic) NSMutableDictionary *avatarToUserOID;
@ -30,7 +27,6 @@
@property(nonatomic, strong) NSArray *marqueeTipTexts;
@end
@implementation MPUnlockViewController {
NSManagedObjectID *_selectedUserOID;
}
@ -932,7 +928,7 @@
}];
MPCheckpoint( MPCheckpointCopyToPasteboard, @{
@"type" : [MPAlgorithmDefault nameOfType:self.emergencyType],
@"type" : NilToNSNull([MPAlgorithmDefault nameOfType:self.emergencyType]),
@"version" : @MPAlgorithmDefaultVersion,
@"emergency" : @YES,
} );

View File

@ -124,7 +124,7 @@
if (message.level >= PearlLogLevelWarn)
MPCheckpoint( @"Problem", @{
@"level" : @(PearlLogLevelStr( message.level )),
@"message" : message.message
@"message" : NilToNSNull(message.message)
} );
return YES;
@ -207,25 +207,25 @@
[[Crashlytics sharedInstance] setObjectValue:[PearlConfig get].reviewedVersion forKey:@"reviewedVersion"];
#ifdef TESTFLIGHT_SDK_VERSION
[TestFlight addCustomEnvironmentInformation:PearlStringNSB([MPConfig get].rememberLogin)
[TestFlight addCustomEnvironmentInformation:PearlStringNSB( [MPConfig get].rememberLogin )
forKey:@"rememberLogin"];
[TestFlight addCustomEnvironmentInformation:PearlStringB([self storeManager].cloudEnabled)
[TestFlight addCustomEnvironmentInformation:PearlStringB( [self storeManager].cloudEnabled )
forKey:@"iCloud"];
[TestFlight addCustomEnvironmentInformation:PearlStringNSB([MPConfig get].iCloudDecided)
[TestFlight addCustomEnvironmentInformation:PearlStringNSB( [MPConfig get].iCloudDecided )
forKey:@"iCloudDecided"];
[TestFlight addCustomEnvironmentInformation:PearlStringNSB([MPiOSConfig get].sendInfo)
[TestFlight addCustomEnvironmentInformation:PearlStringNSB( [MPiOSConfig get].sendInfo )
forKey:@"sendInfo"];
[TestFlight addCustomEnvironmentInformation:PearlStringNSB([MPiOSConfig get].helpHidden)
[TestFlight addCustomEnvironmentInformation:PearlStringNSB( [MPiOSConfig get].helpHidden )
forKey:@"helpHidden"];
[TestFlight addCustomEnvironmentInformation:PearlStringNSB([MPiOSConfig get].showSetup)
[TestFlight addCustomEnvironmentInformation:PearlStringNSB( [MPiOSConfig get].showSetup )
forKey:@"showQuickStart"];
[TestFlight addCustomEnvironmentInformation:PearlStringNSB([PearlConfig get].firstRun)
[TestFlight addCustomEnvironmentInformation:PearlStringNSB( [PearlConfig get].firstRun )
forKey:@"firstRun"];
[TestFlight addCustomEnvironmentInformation:PearlStringNSB([PearlConfig get].launchCount)
[TestFlight addCustomEnvironmentInformation:PearlStringNSB( [PearlConfig get].launchCount )
forKey:@"launchCount"];
[TestFlight addCustomEnvironmentInformation:PearlStringNSB([PearlConfig get].askForReviews)
[TestFlight addCustomEnvironmentInformation:PearlStringNSB( [PearlConfig get].askForReviews )
forKey:@"askForReviews"];
[TestFlight addCustomEnvironmentInformation:PearlStringNSB([PearlConfig get].reviewAfterLaunches)
[TestFlight addCustomEnvironmentInformation:PearlStringNSB( [PearlConfig get].reviewAfterLaunches )
forKey:@"reviewAfterLaunches"];
[TestFlight addCustomEnvironmentInformation:[PearlConfig get].reviewedVersion
forKey:@"reviewedVersion"];
@ -271,17 +271,17 @@
[[MPiOSAppDelegate get] showSetup];
} );
MPCheckpoint(MPCheckpointStarted, @{
@"simulator" : PearlStringB([PearlDeviceUtils isSimulator]),
@"encrypted" : PearlStringB([PearlDeviceUtils isAppEncrypted]),
@"jailbroken" : PearlStringB([PearlDeviceUtils isJailbroken]),
@"platform" : [PearlDeviceUtils platform],
MPCheckpoint( MPCheckpointStarted, @{
@"simulator" : PearlStringB( [PearlDeviceUtils isSimulator] ),
@"encrypted" : PearlStringB( [PearlDeviceUtils isAppEncrypted] ),
@"jailbroken" : PearlStringB( [PearlDeviceUtils isJailbroken] ),
@"platform" : [PearlDeviceUtils platform],
#ifdef APPSTORE
@"legal" : PearlStringB([PearlDeviceUtils isAppEncrypted]),
#else
@"legal" : @"YES",
@"legal" : @"YES",
#endif
});
} );
return YES;
}
@ -737,7 +737,7 @@
NSString *testFlightToken = NSNullToNil([[self testFlightInfo] valueForKeyPath:@"Application Token"]);
if (![testFlightToken length])
wrn(@"TestFlight token not set. Test Flight won't be aware of this test.");
return testFlightToken;
}
@ -785,7 +785,7 @@
#endif
if (![localyticsKey length])
wrn(@"Localytics key not set. Demographics won't be collected.");
return localyticsKey;
}