Skip to content
This repository was archived by the owner on Sep 14, 2020. It is now read-only.

Commit 3ec0fb8

Browse files
committed
fix: guard against api key by avoiding error/session paths
1 parent 4816169 commit 3ec0fb8

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

cocoa/BugsnagReactNative.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config {
216216
NSString *codeBundleId = [RCTConvert NSString:options[@"codeBundleId"]];
217217
BugsnagConfiguration* config = [Bugsnag bugsnagStarted] ? [Bugsnag configuration] : [BugsnagConfiguration new];
218218

219-
if (apiKey != nil && apiKey.length > 0) {
219+
if (apiKey.length > 0) {
220220
config.apiKey = apiKey;
221221
}
222222

cocoa/vendor/bugsnag-cocoa/Source/BugsnagSessionTracker.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ - (void)startNewSession:(NSDate *)date
5858
- (void)trackSession {
5959
[self.sessionStore write:self.currentSession];
6060
self.trackedFirstSession = YES;
61-
61+
6262
if (self.callback) {
6363
self.callback(self.currentSession);
6464
}
@@ -96,7 +96,7 @@ - (void)send {
9696
}
9797
BugsnagSessionTrackingPayload *payload = [[BugsnagSessionTrackingPayload alloc] initWithSessions:sessions];
9898

99-
if (payload.sessions.count > 0) {
99+
if (payload.sessions.count > 0 && self.config.apiKey.length > 0) {
100100
[self.apiClient sendData:payload
101101
withPayload:[payload toJson]
102102
toURL:self.config.sessionURL

cocoa/vendor/bugsnag-cocoa/Source/BugsnagSink.m

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ - (void)filterReports:(NSArray *)reports
9595
}
9696
#pragma clang diagnostic pop
9797

98-
if (reportData == nil) {
98+
if (reportData == nil || [reportData count] <= 0) {
9999
if (onCompletion) {
100100
onCompletion(@[], YES, nil);
101101
}
@@ -113,17 +113,20 @@ - (void)filterReports:(NSArray *)reports
113113
// Generates the payload for notifying Bugsnag
114114
- (NSDictionary *)getBodyFromReports:(NSArray *)reports {
115115
NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
116-
BSGDictSetSafeObject(data, [Bugsnag notifier].details, BSGKeyNotifier);
117-
BSGDictSetSafeObject(data, [Bugsnag notifier].configuration.apiKey, BSGKeyApiKey);
118116

119-
NSMutableArray *formatted =
120-
[[NSMutableArray alloc] initWithCapacity:[reports count]];
117+
if ([Bugsnag notifier].configuration.apiKey.length > 0) {
118+
BSGDictSetSafeObject(data, [Bugsnag notifier].details, BSGKeyNotifier);
119+
BSGDictSetSafeObject(data, [Bugsnag notifier].configuration.apiKey, BSGKeyApiKey);
121120

122-
for (BugsnagCrashReport *report in reports) {
123-
BSGArrayAddSafeObject(formatted, [report toJson]);
124-
}
121+
NSMutableArray *formatted =
122+
[[NSMutableArray alloc] initWithCapacity:[reports count]];
123+
124+
for (BugsnagCrashReport *report in reports) {
125+
BSGArrayAddSafeObject(formatted, [report toJson]);
126+
}
125127

126-
BSGDictSetSafeObject(data, formatted, BSGKeyEvents);
128+
BSGDictSetSafeObject(data, formatted, BSGKeyEvents);
129+
}
127130
return data;
128131
}
129132

0 commit comments

Comments
 (0)