Skip to content

Commit

Permalink
fix(react-native): update bugsnag-cocoa
Browse files Browse the repository at this point in the history
Updates the vendored bugsnag-cocoa to 6.1.4 primarily to incorporate the following fixes:
- Copy the metadata observer list rather than mutating it directly.
  • Loading branch information
djskinner committed Sep 16, 2020
1 parent 3f482dd commit 66147ab
Show file tree
Hide file tree
Showing 23 changed files with 374 additions and 175 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixed

- (react-native): Update bugsnag-cocoa to 6.1.4. Fixes: Copy the metadata observer list rather than mutating it directly.

## 7.3.4 (2020-09-10)

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/ios/.bugsnag-cocoa-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b248306c5438cac7265913ac4fa80ad938fdb6bf
c4453b414e595f0c0a07ce36a6d07f3144df6089
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Bugsnag",
"version": "6.1.2",
"version": "6.1.4",
"summary": "The Bugsnag crash reporting framework for Apple platforms.",
"homepage": "https://bugsnag.com",
"license": "MIT",
Expand All @@ -9,7 +9,7 @@
},
"source": {
"git": "https://github.com/bugsnag/bugsnag-cocoa.git",
"tag": "v6.1.2"
"tag": "v6.1.4"
},
"frameworks": [
"Foundation",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#import "Private.h"
#import "BugsnagErrorTypes.h"
#import "BSG_RFC3339DateTool.h"
#import "BSGJSONSerialization.h"
#import "BugsnagKeys.h"
#import "BugsnagCollections.h"

@interface BSGOutOfMemoryWatchdog ()
@property(nonatomic, getter=isWatching) BOOL watching;
Expand Down Expand Up @@ -124,32 +127,32 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary<NSString *, id> *)change
context:(void *)context {
self.cachedFileInfo[@"app"][@"releaseStage"] = change[NSKeyValueChangeNewKey];
self.cachedFileInfo[BSGKeyApp][BSGKeyReleaseStage] = change[NSKeyValueChangeNewKey];
[self writeSentinelFile];
}

- (void)handleTransitionToActive:(NSNotification *)note {
self.cachedFileInfo[@"app"][@"isActive"] = @YES;
self.cachedFileInfo[BSGKeyApp][@"isActive"] = @YES;
[self writeSentinelFile];
}

- (void)handleTransitionToInactive:(NSNotification *)note {
self.cachedFileInfo[@"app"][@"isActive"] = @NO;
self.cachedFileInfo[BSGKeyApp][@"isActive"] = @NO;
[self writeSentinelFile];
}

- (void)handleTransitionToForeground:(NSNotification *)note {
self.cachedFileInfo[@"app"][@"inForeground"] = @YES;
self.cachedFileInfo[BSGKeyApp][@"inForeground"] = @YES;
[self writeSentinelFile];
}

- (void)handleTransitionToBackground:(NSNotification *)note {
self.cachedFileInfo[@"app"][@"inForeground"] = @NO;
self.cachedFileInfo[BSGKeyApp][@"inForeground"] = @NO;
[self writeSentinelFile];
}

- (void)handleLowMemoryChange:(NSNotification *)note {
self.cachedFileInfo[@"device"][@"lowMemory"] = [BSG_RFC3339DateTool
self.cachedFileInfo[BSGKeyDevice][@"lowMemory"] = [BSG_RFC3339DateTool
stringFromDate:[NSDate date]];
[self writeSentinelFile];
}
Expand All @@ -158,16 +161,16 @@ - (void)handleUpdateSession:(NSNotification *)note {
id session = [note object];
NSMutableDictionary *cache = (id)self.cachedFileInfo;
if (session) {
cache[@"session"] = session;
cache[BSGKeySession] = session;
} else {
[cache removeObjectForKey:@"session"];
[cache removeObjectForKey:BSGKeySession];
}
[self writeSentinelFile];
}

- (void)setCodeBundleId:(NSString *)codeBundleId {
_codeBundleId = codeBundleId;
self.cachedFileInfo[@"app"][@"codeBundleId"] = codeBundleId;
BSGDictInsertIfNotNil(self.cachedFileInfo[BSGKeyApp], codeBundleId, BSGKeyCodeBundleId);

if ([self isWatching]) {
[self writeSentinelFile];
Expand Down Expand Up @@ -224,7 +227,7 @@ - (NSDictionary *)readSentinelFile {
bsg_log_err(@"Failed to read oom watchdog file: %@", error);
return nil;
}
NSDictionary *contents = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
NSDictionary *contents = [BSGJSONSerialization JSONObjectWithData:data options:0 error:&error];
if (error) {
bsg_log_err(@"Failed to read oom watchdog file: %@", error);
return nil;
Expand All @@ -235,11 +238,11 @@ - (NSDictionary *)readSentinelFile {

- (void)writeSentinelFile {
NSError *error = nil;
if (![NSJSONSerialization isValidJSONObject:self.cachedFileInfo]) {
if (![BSGJSONSerialization isValidJSONObject:self.cachedFileInfo]) {
bsg_log_err(@"Cached oom watchdog data cannot be written as JSON");
return;
}
NSData *data = [NSJSONSerialization dataWithJSONObject:self.cachedFileInfo options:0 error:&error];
NSData *data = [BSGJSONSerialization dataWithJSONObject:self.cachedFileInfo options:0 error:&error];
if (error) {
bsg_log_err(@"Cached oom watchdog data cannot be written as JSON: %@", error);
return;
Expand All @@ -252,13 +255,13 @@ - (NSMutableDictionary *)generateCacheInfoWithConfig:(BugsnagConfiguration *)con
NSMutableDictionary *cache = [NSMutableDictionary new];
NSMutableDictionary *app = [NSMutableDictionary new];

app[@"id"] = systemInfo[@BSG_KSSystemField_BundleID] ?: @"";
app[@"name"] = systemInfo[@BSG_KSSystemField_BundleName] ?: @"";
app[@"releaseStage"] = config.releaseStage;
app[@"version"] = systemInfo[@BSG_KSSystemField_BundleShortVersion] ?: @"";
app[@"bundleVersion"] = systemInfo[@BSG_KSSystemField_BundleVersion] ?: @"";
app[BSGKeyId] = systemInfo[@BSG_KSSystemField_BundleID] ?: @"";
app[BSGKeyName] = systemInfo[@BSG_KSSystemField_BundleName] ?: @"";
app[BSGKeyReleaseStage] = config.releaseStage;
app[BSGKeyVersion] = systemInfo[@BSG_KSSystemField_BundleShortVersion] ?: @"";
app[BSGKeyBundleVersion] = systemInfo[@BSG_KSSystemField_BundleVersion] ?: @"";
// 'codeBundleId' only (optionally) exists for React Native clients and defaults otherwise to nil
app[@"codeBundleId"] = self.codeBundleId;
BSGDictInsertIfNotNil(app, self.codeBundleId, BSGKeyCodeBundleId);
#if BSGOOMAvailable
UIApplicationState state = [BSG_KSSystemInfo currentAppState];
app[@"inForeground"] = @([BSG_KSSystemInfo isInForeground:state]);
Expand All @@ -267,11 +270,11 @@ - (NSMutableDictionary *)generateCacheInfoWithConfig:(BugsnagConfiguration *)con
app[@"inForeground"] = @YES;
#endif
#if BSG_PLATFORM_TVOS
app[@"type"] = @"tvOS";
app[BSGKeyType] = @"tvOS";
#elif BSG_PLATFORM_IOS
app[@"type"] = @"iOS";
app[BSGKeyType] = @"iOS";
#endif
cache[@"app"] = app;
cache[BSGKeyApp] = app;

NSMutableDictionary *device = [NSMutableDictionary new];
device[@"id"] = systemInfo[@BSG_KSSystemField_DeviceAppHash];
Expand All @@ -289,7 +292,7 @@ - (NSMutableDictionary *)generateCacheInfoWithConfig:(BugsnagConfiguration *)con
#else
device[@"simulator"] = @NO;
#endif
cache[@"device"] = device;
cache[BSGKeyDevice] = device;

return cache;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "BugsnagBreadcrumb.h"
#import "BugsnagLogger.h"
#import "Private.h"
#import "BSGJSONSerialization.h"

@interface BugsnagConfiguration ()
@property(nonatomic) NSMutableArray *onBreadcrumbBlocks;
Expand Down Expand Up @@ -59,7 +60,6 @@ - (void)addBreadcrumbWithBlock:
return;
}
BugsnagBreadcrumb *crumb = [BugsnagBreadcrumb breadcrumbWithBlock:block];

if (crumb != nil && [self shouldSendBreadcrumb:crumb]) {
dispatch_barrier_sync(self.readWriteQueue, ^{
if ((self.breadcrumbs.count > 0) &&
Expand All @@ -72,9 +72,9 @@ - (void)addBreadcrumbWithBlock:
if (self.cachePath != nil) {
static NSString *const arrayKeyPath = @"objectValue";
NSArray *items = [self.breadcrumbs valueForKeyPath:arrayKeyPath];
if ([NSJSONSerialization isValidJSONObject:items]) {
if ([BSGJSONSerialization isValidJSONObject:items]) {
NSError *error = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:items
NSData *data = [BSGJSONSerialization dataWithJSONObject:items
options:0
error:&error];
[data writeToFile:self.cachePath atomically:NO];
Expand Down Expand Up @@ -106,7 +106,7 @@ - (NSArray *)cachedBreadcrumbs {
NSError *error = nil;
NSData *data = [NSData dataWithContentsOfFile:self.cachePath options:0 error:&error];
if (error == nil) {
cache = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
cache = [BSGJSONSerialization JSONObjectWithData:data options:0 error:&error];
}
if (error != nil) {
bsg_log_err(@"Failed to read breadcrumbs from disk: %@", error);
Expand All @@ -123,7 +123,7 @@ - (NSArray *)arrayValue {
NSDictionary *objectValue = [crumb objectValue];
NSError *error = nil;
@try {
if (![NSJSONSerialization isValidJSONObject:objectValue]) {
if (![BSGJSONSerialization isValidJSONObject:objectValue]) {
bsg_log_err(@"Unable to serialize breadcrumb: Not a valid "
@"JSON object");
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#import "BugsnagCollections.h"
#import "BSG_KSCrashReport.h"
#import "BSG_KSCrash.h"
#import "BSGJSONSerialization.h"

#if BSG_PLATFORM_IOS
#import <UIKit/UIKit.h>
Expand Down Expand Up @@ -239,13 +240,13 @@ void BSSerializeDataCrashHandler(const BSG_KSCrashReportWriter *writer, int type
* @param destination target location of the data
*/
void BSSerializeJSONDictionary(NSDictionary *dictionary, char **destination) {
if (![NSJSONSerialization isValidJSONObject:dictionary]) {
if (![BSGJSONSerialization isValidJSONObject:dictionary]) {
bsg_log_err(@"could not serialize metadata: is not valid JSON object");
return;
}
@try {
NSError *error;
NSData *json = [NSJSONSerialization dataWithJSONObject:dictionary
NSData *json = [BSGJSONSerialization dataWithJSONObject:dictionary
options:0
error:&error];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "BugsnagKeys.h"
#import "BugsnagLogger.h"
#import "Private.h"
#import "BSGJSONSerialization.h"

@interface BSGDelayOperation : NSOperation
@end
Expand Down Expand Up @@ -59,7 +60,7 @@ - (void)sendItems:(NSUInteger)count
@try {
NSError *error = nil;
NSData *jsonData =
[NSJSONSerialization dataWithJSONObject:payload
[BSGJSONSerialization dataWithJSONObject:payload
options:0
error:&error];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// BSGJSONSerialization.h
// Bugsnag
//
// Created by Karl Stenerud on 03.09.20.
// Copyright © 2020 Bugsnag Inc. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/* Wraps NSJSONSerialization to trap any exceptions and return them as errors.
*
* NSJSONSerialization sometimes returns errors and sometimes throws exceptions,
* with no specification as to which mechanism will trigger for what kinds of errors.
* This wrapper catches all exceptions and forces everything to be returned as an error.
*/
@interface BSGJSONSerialization : NSObject

/* Returns YES if the given object can be converted to JSON data, NO otherwise. The object must have the following properties:
- Top level object is an NSArray or NSDictionary
- All objects are NSString, NSNumber, NSArray, NSDictionary, or NSNull
- All dictionary keys are NSStrings
- NSNumbers are not NaN or infinity
Other rules may apply. Calling this method or attempting a conversion are the definitive ways to tell if a given object can be converted to JSON data.
*/
+ (BOOL)isValidJSONObject:(id)obj;

/* Generate JSON data from a Foundation object. If the object will not produce valid JSON then an error will be returned. Setting the NSJSONWritingPrettyPrinted option will generate JSON with whitespace designed to make the output more readable. If that option is not set, the most compact possible JSON will be generated. If an error occurs, the error parameter will be set and the return value will be nil. The resulting data is a encoded in UTF-8.
*/
+ (nullable NSData *)dataWithJSONObject:(id)obj options:(NSJSONWritingOptions)opt error:(NSError **)error;

/* Create a Foundation object from JSON data. Set the NSJSONReadingAllowFragments option if the parser should allow top-level objects that are not an NSArray or NSDictionary. Setting the NSJSONReadingMutableContainers option will make the parser generate mutable NSArrays and NSDictionaries. Setting the NSJSONReadingMutableLeaves option will make the parser generate mutable NSString objects. If an error occurs during the parse, then the error parameter will be set and the result will be nil.
The data must be in one of the 5 supported encodings listed in the JSON specification: UTF-8, UTF-16LE, UTF-16BE, UTF-32LE, UTF-32BE. The data may or may not have a BOM. The most efficient encoding to use for parsing is UTF-8, so if you have a choice in encoding the data passed to this method, use UTF-8.
*/
+ (nullable id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error;

/* Write JSON data into a stream. The stream should be opened and configured. The return value is the number of bytes written to the stream, or 0 on error. All other behavior of this method is the same as the dataWithJSONObject:options:error: method.
*/
+ (NSInteger)writeJSONObject:(id)obj toStream:(NSOutputStream *)stream options:(NSJSONWritingOptions)opt error:(NSError **)error;

/* Create a JSON object from JSON data stream. The stream should be opened and configured. All other behavior of this method is the same as the JSONObjectWithData:options:error: method.
*/
+ (nullable id)JSONObjectWithStream:(NSInputStream *)stream options:(NSJSONReadingOptions)opt error:(NSError **)error;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// BSGJSONSerialization.m
// Bugsnag
//
// Created by Karl Stenerud on 03.09.20.
// Copyright © 2020 Bugsnag Inc. All rights reserved.
//

#import "BSGJSONSerialization.h"
#import "BugsnagLogger.h"

@implementation BSGJSONSerialization

static NSError* wrapException(NSException* exception) {
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: exception.description,
NSUnderlyingErrorKey: exception,
};

return [NSError errorWithDomain:@"com.bugsnag" code:1 userInfo:userInfo];
}

+ (BOOL)isValidJSONObject:(id)obj {
@try {
return [NSJSONSerialization isValidJSONObject:obj];
} @catch (NSException *exception) {
return false;
}
}

+ (nullable NSData *)dataWithJSONObject:(id)obj options:(NSJSONWritingOptions)opt error:(NSError **)error {
@try {
return [NSJSONSerialization dataWithJSONObject:obj options:opt error:error];
} @catch (NSException *exception) {
*error = wrapException(exception);
return nil;
}
}

+ (nullable id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error {
@try {
return [NSJSONSerialization JSONObjectWithData:data options:opt error:error];
} @catch (NSException *exception) {
*error = wrapException(exception);
return nil;
}
}

+ (NSInteger)writeJSONObject:(id)obj toStream:(NSOutputStream *)stream options:(NSJSONWritingOptions)opt error:(NSError **)error {
@try {
return [NSJSONSerialization writeJSONObject:obj toStream:stream options:opt error:error];
} @catch (NSException *exception) {
*error = wrapException(exception);
return 0;
}
}

+ (nullable id)JSONObjectWithStream:(NSInputStream *)stream options:(NSJSONReadingOptions)opt error:(NSError **)error {
@try {
return [NSJSONSerialization JSONObjectWithStream:stream options:opt error:error];
} @catch (NSException *exception) {
*error = wrapException(exception);
return nil;
}
}

@end
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "BSGSerialization.h"
#import "BugsnagLogger.h"
#import "BSGJSONSerialization.h"

BOOL BSGIsSanitizedType(id obj) {
static dispatch_once_t onceToken;
Expand Down Expand Up @@ -66,7 +67,7 @@ id BSGSanitizeObject(id obj) {
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding] ;
if (data != nil) {
NSError *error;
NSDictionary *decode = [NSJSONSerialization JSONObjectWithData:data
NSDictionary *decode = [BSGJSONSerialization JSONObjectWithData:data
options:0
error:&error];
if (error != nil) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ extern NSString *const BSGDefaultNotifyUrl;
extern NSString *const BSGKeyAction;
extern NSString *const BSGKeyApiKey;
extern NSString *const BSGKeyApp;
extern NSString *const BSGKeyAppState;
extern NSString *const BSGKeyAppType;
extern NSString *const BSGKeyAppVersion;
extern NSString *const BSGKeyAttributes;
Expand Down
Loading

0 comments on commit 66147ab

Please sign in to comment.