From 9c4671f2e3a63c0f155d9b2511192d0b5fa7f760 Mon Sep 17 00:00:00 2001 From: Nelson Billing Date: Wed, 9 Sep 2020 14:39:32 -0700 Subject: Change JSON serialization error check. - Mac OS symupload used to check for errors in JSON serialization by inspecting the "error" out parameter of the serialization function. Now it checks the returned data for "nil". - Similar change for the HTTP request that's made in the same function. Change-Id: I86f50ef44e60ee119c302e0614b115a8d35e9b5b Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/2390753 Reviewed-by: Mark Mentovai --- src/common/mac/SymbolCollectorClient.m | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/common/mac/SymbolCollectorClient.m b/src/common/mac/SymbolCollectorClient.m index b135cdeb..5926d2ad 100644 --- a/src/common/mac/SymbolCollectorClient.m +++ b/src/common/mac/SymbolCollectorClient.m @@ -202,32 +202,37 @@ NSDictionary* jsonDictionary = [NSDictionary dictionaryWithObjectsAndKeys:symbolIdDictionary, @"symbol_id", type, @"symbol_upload_type", nil]; - NSError* error; + NSError* error = nil; NSData* jsonData = [NSJSONSerialization dataWithJSONObject:jsonDictionary options:NSJSONWritingPrettyPrinted error:&error]; - if (error) { + if (jsonData == nil) { + fprintf(stdout, "Error: %s\n", [[error localizedDescription] UTF8String]); fprintf(stdout, "Failed to complete upload. Could not write JSON payload.\n"); return CompleteUploadResultError; } + NSString* body = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; - HTTPSimplePostRequest* postRequest = [[HTTPSimplePostRequest alloc] initWithURL:URL]; [postRequest setBody:body]; [postRequest setContentType:@"application/json"]; - error = nil; NSData* data = [postRequest send:&error]; + if (data == nil) { + fprintf(stdout, "Error: %s\n", [[error localizedDescription] UTF8String]); + fprintf(stdout, "Failed to complete upload URL.\n"); + return CompleteUploadResultError; + } + NSString* result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; int responseCode = [[postRequest response] statusCode]; [postRequest release]; - - if (error || responseCode != 200) { + if (responseCode != 200) { fprintf(stdout, "Failed to complete upload URL.\n"); fprintf(stdout, "Response code: %d\n", responseCode); fprintf(stdout, "Response:\n"); -- cgit v1.2.1