Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Crashlytics/Crashlytics/Components/FIRCLSContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
initData.previouslyCrashedFileRootPath = [fileManager rootPath];
initData.errorsEnabled = [settings errorReportingEnabled];
initData.customExceptionsEnabled = [settings customExceptionsEnabled];
initData.machExceptionDefaultBehavior = [settings machExceptionDefaultBehavior];
initData.maxCustomExceptions = [settings maxCustomExceptions];
initData.maxErrorLogSize = [settings errorLogBufferSize];
initData.maxLogSize = [settings logBufferSize];
Expand Down Expand Up @@ -190,7 +191,9 @@
// TODO: remove EXCEPTION_DEFAULT support when we bump min MacOS support to 12+
_firclsContext.readonly->machException.behavior = EXCEPTION_DEFAULT;
if (@available(macOS 12, *)) {
_firclsContext.readonly->machException.behavior = EXCEPTION_IDENTITY_PROTECTED;
if (!initData.machExceptionDefaultBehavior) {
_firclsContext.readonly->machException.behavior = EXCEPTION_IDENTITY_PROTECTED;
}
}
FIRCLSMachExceptionInit(&_firclsContext.readonly->machException);
});
Expand Down
3 changes: 2 additions & 1 deletion Crashlytics/Crashlytics/FIRCrashlytics.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ - (instancetype)initWithApp:(FIRApp *)app

FIRCLSApplicationIdentifierModel *appModel = [[FIRCLSApplicationIdentifierModel alloc] init];
FIRCLSSettings *settings = [[FIRCLSSettings alloc] initWithFileManager:_fileManager
appIDModel:appModel];
appIDModel:appModel
appInfo:appInfo];

FIRCLSOnDemandModel *onDemandModel =
[[FIRCLSOnDemandModel alloc] initWithFIRCLSSettings:settings fileManager:_fileManager];
Expand Down
1 change: 1 addition & 0 deletions Crashlytics/Crashlytics/Helpers/FIRCLSContextInitData.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, copy) NSString* betaToken;
@property(nonatomic) BOOL errorsEnabled;
@property(nonatomic) BOOL customExceptionsEnabled;
@property(nonatomic) BOOL machExceptionDefaultBehavior;
@property(nonatomic) uint32_t maxCustomExceptions;
@property(nonatomic) uint32_t maxErrorLogSize;
@property(nonatomic) uint32_t maxLogSize;
Expand Down
9 changes: 8 additions & 1 deletion Crashlytics/Crashlytics/Models/FIRCLSSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager
appIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel;
appIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel
appInfo:(NSDictionary *)appInfo;

/**
* Recreates the settings dictionary by re-reading the settings file from persistent storage. This
Expand Down Expand Up @@ -78,6 +79,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property(nonatomic, readonly) BOOL customExceptionsEnabled;

/**
* When this is true, Crashlytics will fallback to EXCEPTION_DEFAULT
* for mach exception handler instead of EXCEPTION_IDENTITY_PROTECTED
*/
@property(nonatomic) BOOL machExceptionDefaultBehavior;

/**
* When this is true, Crashlytics will collect data from MetricKit
*/
Expand Down
17 changes: 16 additions & 1 deletion Crashlytics/Crashlytics/Models/FIRCLSSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
NSString *const GoogleAppIDKey = @"google_app_id";
NSString *const BuildInstanceID = @"build_instance_id";
NSString *const AppVersion = @"app_version";
NSString *const FirebaseCrashlyticsMachDefaultBehaviorKey =
@"FirebaseCrashlyticsMachDefaultBehavior";

@interface FIRCLSSettings ()

Expand All @@ -47,21 +49,34 @@ @interface FIRCLSSettings ()
@implementation FIRCLSSettings

- (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager
appIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel {
appIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel
appInfo:(NSDictionary *)appInfo {
return
[self initWithFileManager:fileManager
appIDModel:appIDModel
appInfo:appInfo
deletionQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)];
}

- (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager
appIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel
appInfo:(NSDictionary *)appInfo
deletionQueue:(dispatch_queue_t)deletionQueue {
self = [super init];
if (!self) {
return nil;
}

// Configure the Mach exception message receiving behavior from Info.plist the mach exception
// message receiving behavior
self.machExceptionDefaultBehavior = false;
id crashlyticsMachDefaultBehavior =
[appInfo objectForKey:FirebaseCrashlyticsMachDefaultBehaviorKey];
if ([crashlyticsMachDefaultBehavior isKindOfClass:[NSString class]] ||
[crashlyticsMachDefaultBehavior isKindOfClass:[NSNumber class]]) {
self.machExceptionDefaultBehavior = [crashlyticsMachDefaultBehavior boolValue];
}

_fileManager = fileManager;
_appIDModel = appIDModel;

Expand Down
3 changes: 2 additions & 1 deletion Crashlytics/UnitTests/FIRCLSContextManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ - (void)setUp {

FIRCLSApplicationIdentifierModel *appIDModel = [[FIRCLSApplicationIdentifierModel alloc] init];
_mockSettings = [[FIRCLSMockSettings alloc] initWithFileManager:self.fileManager
appIDModel:appIDModel];
appIDModel:appIDModel
appInfo:[[NSDictionary alloc] init]];

// NSString *name = @"exception_model_report";
NSString *reportPath =
Expand Down
4 changes: 3 additions & 1 deletion Crashlytics/UnitTests/FIRCLSMetricKitManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ - (void)setUp {
[[FIRMockGDTCORTransport alloc] initWithMappingID:@"id" transformers:nil target:0];
FIRCLSApplicationIdentifierModel *appIDModel = [[FIRCLSApplicationIdentifierModel alloc] init];
FIRCLSMockSettings *mockSettings =
[[FIRCLSMockSettings alloc] initWithFileManager:self.fileManager appIDModel:appIDModel];
[[FIRCLSMockSettings alloc] initWithFileManager:self.fileManager
appIDModel:appIDModel
appInfo:[[NSDictionary alloc] init]];

// Allow nil values only in tests
#pragma clang diagnostic push
Expand Down
3 changes: 2 additions & 1 deletion Crashlytics/UnitTests/FIRCLSOnDemandModelTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ - (void)setUp {

FIRCLSApplicationIdentifierModel *appIDModel = [[FIRCLSApplicationIdentifierModel alloc] init];
_mockSettings = [[FIRCLSMockSettings alloc] initWithFileManager:self.fileManager
appIDModel:appIDModel];
appIDModel:appIDModel
appInfo:[[NSDictionary alloc] init]];
_onDemandModel = [[FIRCLSMockOnDemandModel alloc] initWithFIRCLSSettings:_mockSettings
fileManager:_fileManager
sleepBlock:^(int delay){
Expand Down
3 changes: 2 additions & 1 deletion Crashlytics/UnitTests/FIRCLSReportManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ - (void)setUp {
[[FIRMockGDTCORTransport alloc] initWithMappingID:@"id" transformers:nil target:0];
self.appIDModel = [[FIRCLSApplicationIdentifierModel alloc] init];
self.mockSettings = [[FIRCLSMockSettings alloc] initWithFileManager:self.fileManager
appIDModel:self.appIDModel];
appIDModel:self.appIDModel
appInfo:[[NSDictionary alloc] init]];

// Allow nil values only in tests
#pragma clang diagnostic push
Expand Down
3 changes: 2 additions & 1 deletion Crashlytics/UnitTests/FIRCLSReportUploaderTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ - (void)setUp {
FABMockApplicationIdentifierModel *appIDModel = [[FABMockApplicationIdentifierModel alloc] init];
self.queue = [NSOperationQueue new];
self.mockSettings = [[FIRCLSMockSettings alloc] initWithFileManager:self.fileManager
appIDModel:appIDModel];
appIDModel:appIDModel
appInfo:[[NSDictionary alloc] init]];
self.mockDataTransport = [[FIRMockGDTCORTransport alloc] initWithMappingID:@"1206"
transformers:nil
target:kGDTCORTargetCSH];
Expand Down
33 changes: 33 additions & 0 deletions Crashlytics/UnitTests/FIRCLSSettingsTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ @interface FIRCLSSettings (Testing)

- (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager
appIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel
appInfo:(nonnull NSDictionary *)appInfo
deletionQueue:(dispatch_queue_t)deletionQueue;

@end
Expand Down Expand Up @@ -90,6 +91,7 @@ - (void)setUp {
_settings = [[FIRCLSSettings alloc]
initWithFileManager:_fileManager
appIDModel:_appIDModel
appInfo:[[NSDictionary alloc] init]
deletionQueue:dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0)];
}

Expand All @@ -103,6 +105,7 @@ - (void)testDefaultSettings {
XCTAssertTrue(self.settings.errorReportingEnabled);
XCTAssertTrue(self.settings.customExceptionsEnabled);
XCTAssertFalse(self.settings.metricKitCollectionEnabled);
XCTAssertFalse(self.settings.machExceptionDefaultBehavior);

XCTAssertEqual(self.settings.errorLogBufferSize, 64 * 1000);
XCTAssertEqual(self.settings.logBufferSize, 64 * 1000);
Expand Down Expand Up @@ -486,4 +489,34 @@ - (void)testLegacyReportEndpointSettingsWithUnknownValue {
XCTAssertNil(error, "%@", error);
}

- (void)testMachExceptionBehaviorFromAppInfo {
// The key is defined in FIRCLSSettings.m, so we'll redefine it here for the test.
NSString *const FirebaseCrashlyticsMachDefaultBehaviorKey =
@"FirebaseCrashlyticsMachDefaultBehavior";

NSDictionary *appInfoWithSetting = @{FirebaseCrashlyticsMachDefaultBehaviorKey : @YES};
_settings = [[FIRCLSSettings alloc]
initWithFileManager:_fileManager
appIDModel:_appIDModel
appInfo:appInfoWithSetting
deletionQueue:dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0)];
XCTAssertTrue(self.settings.machExceptionDefaultBehavior);

NSDictionary *appInfoWithSettingString = @{FirebaseCrashlyticsMachDefaultBehaviorKey : @"true"};
_settings = [[FIRCLSSettings alloc]
initWithFileManager:_fileManager
appIDModel:_appIDModel
appInfo:appInfoWithSettingString
deletionQueue:dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0)];
XCTAssertTrue(self.settings.machExceptionDefaultBehavior);

NSDictionary *appInfoWithSettingFalse = @{FirebaseCrashlyticsMachDefaultBehaviorKey : @NO};
_settings = [[FIRCLSSettings alloc]
initWithFileManager:_fileManager
appIDModel:_appIDModel
appInfo:appInfoWithSettingFalse
deletionQueue:dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0)];
XCTAssertFalse(self.settings.machExceptionDefaultBehavior);
}

@end
3 changes: 2 additions & 1 deletion Crashlytics/UnitTests/FIRRecordExceptionModelTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ - (void)setUp {

FABMockApplicationIdentifierModel *appIDModel = [[FABMockApplicationIdentifierModel alloc] init];
self.mockSettings = [[FIRCLSMockSettings alloc] initWithFileManager:self.fileManager
appIDModel:appIDModel];
appIDModel:appIDModel
appInfo:[[NSDictionary alloc] init]];

NSString *name = @"exception_model_report";
self.reportPath = [self.fileManager.rootPath stringByAppendingPathComponent:name];
Expand Down
Loading