Skip to content

Commit 41a7091

Browse files
authored
Fix Debug Logging Crash (#448)
• The SDK will print (verbose mode) log statements for every HTTP request the SDK makes • To be more informative, the SDK prints all HTTP request parameters as prettified JSON. However when serializing the parameters to JSON, the SDK was not checking to see if an error occurred which could lead to crashes in rare circumstances.
1 parent 8bab228 commit 41a7091

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignalClient.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,14 @@ - (void)prettyPrintDebugStatementWithRequest:(OneSignalRequest *)request {
245245
return;
246246

247247
NSError *error;
248+
248249
let data = [NSJSONSerialization dataWithJSONObject:request.parameters options:NSJSONWritingPrettyPrinted error:&error];
250+
251+
if (error || !data) {
252+
[OneSignal onesignal_Log:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"Unable to print the parameters of %@ with JSON serialization error: %@.", NSStringFromClass([request class]), error.description]];
253+
return;
254+
}
255+
249256
let jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
250257

251258
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"HTTP Request (%@) with URL: %@, with parameters: %@", NSStringFromClass([request class]), request.urlRequest.URL.absoluteString, jsonString]];

0 commit comments

Comments
 (0)