Fix NPE in debug log uploader.

pull/1/head
Matthew Chen 7 years ago
parent 2c60a57491
commit b4fc0cddcd

@ -80,23 +80,28 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error
parameters:nil parameters:nil
progress:nil progress:nil
success:^(NSURLSessionDataTask *task, id _Nullable responseObject) { success:^(NSURLSessionDataTask *task, id _Nullable responseObject) {
DebugLogUploader *strongSelf = weakSelf;
if (!strongSelf) {
return;
}
if (![responseObject isKindOfClass:[NSDictionary class]]) { if (![responseObject isKindOfClass:[NSDictionary class]]) {
DDLogError(@"%@ Invalid response: %@, %@", weakSelf.logTag, urlString, responseObject); DDLogError(@"%@ Invalid response: %@, %@", strongSelf.logTag, urlString, responseObject);
[weakSelf [strongSelf
failWithError:OWSErrorWithCodeDescription(OWSErrorCodeDebugLogUploadFailed, @"Invalid response")]; failWithError:OWSErrorWithCodeDescription(OWSErrorCodeDebugLogUploadFailed, @"Invalid response")];
return; return;
} }
NSString *uploadUrl = responseObject[@"url"]; NSString *uploadUrl = responseObject[@"url"];
if (![uploadUrl isKindOfClass:[NSString class]] || uploadUrl.length < 1) { if (![uploadUrl isKindOfClass:[NSString class]] || uploadUrl.length < 1) {
DDLogError(@"%@ Invalid response: %@, %@", weakSelf.logTag, urlString, responseObject); DDLogError(@"%@ Invalid response: %@, %@", strongSelf.logTag, urlString, responseObject);
[weakSelf [strongSelf
failWithError:OWSErrorWithCodeDescription(OWSErrorCodeDebugLogUploadFailed, @"Invalid response")]; failWithError:OWSErrorWithCodeDescription(OWSErrorCodeDebugLogUploadFailed, @"Invalid response")];
return; return;
} }
NSDictionary *fields = responseObject[@"fields"]; NSDictionary *fields = responseObject[@"fields"];
if (![fields isKindOfClass:[NSDictionary class]] || fields.count < 1) { if (![fields isKindOfClass:[NSDictionary class]] || fields.count < 1) {
DDLogError(@"%@ Invalid response: %@, %@", weakSelf.logTag, urlString, responseObject); DDLogError(@"%@ Invalid response: %@, %@", strongSelf.logTag, urlString, responseObject);
[weakSelf [strongSelf
failWithError:OWSErrorWithCodeDescription(OWSErrorCodeDebugLogUploadFailed, @"Invalid response")]; failWithError:OWSErrorWithCodeDescription(OWSErrorCodeDebugLogUploadFailed, @"Invalid response")];
return; return;
} }
@ -104,27 +109,33 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error
NSString *fieldValue = fields[fieldName]; NSString *fieldValue = fields[fieldName];
if (![fieldName isKindOfClass:[NSString class]] || fieldName.length < 1 if (![fieldName isKindOfClass:[NSString class]] || fieldName.length < 1
|| ![fieldValue isKindOfClass:[NSString class]] || fieldValue.length < 1) { || ![fieldValue isKindOfClass:[NSString class]] || fieldValue.length < 1) {
DDLogError(@"%@ Invalid response: %@, %@", weakSelf.logTag, urlString, responseObject); DDLogError(@"%@ Invalid response: %@, %@", strongSelf.logTag, urlString, responseObject);
[weakSelf failWithError:OWSErrorWithCodeDescription( [strongSelf failWithError:OWSErrorWithCodeDescription(
OWSErrorCodeDebugLogUploadFailed, @"Invalid response")]; OWSErrorCodeDebugLogUploadFailed, @"Invalid response")];
return; return;
} }
} }
NSString *_Nullable uploadKey = fields[@"key"]; NSString *_Nullable uploadKey = fields[@"key"];
if (![uploadKey isKindOfClass:[NSString class]] || uploadKey.length < 1) { if (![uploadKey isKindOfClass:[NSString class]] || uploadKey.length < 1) {
DDLogError(@"%@ Invalid response: %@, %@", weakSelf.logTag, urlString, responseObject); DDLogError(@"%@ Invalid response: %@, %@", strongSelf.logTag, urlString, responseObject);
[weakSelf [strongSelf
failWithError:OWSErrorWithCodeDescription(OWSErrorCodeDebugLogUploadFailed, @"Invalid response")]; failWithError:OWSErrorWithCodeDescription(OWSErrorCodeDebugLogUploadFailed, @"Invalid response")];
return; return;
} }
// Add a file extension to the upload's key. // Add a file extension to the upload's key.
NSString *fileExtension = weakSelf.fileUrl.lastPathComponent.pathExtension; NSString *fileExtension = strongSelf.fileUrl.lastPathComponent.pathExtension;
if (fileExtension.length < 1) {
DDLogError(@"%@ Invalid response: %@, %@", strongSelf.logTag, urlString, responseObject);
[strongSelf
failWithError:OWSErrorWithCodeDescription(OWSErrorCodeDebugLogUploadFailed, @"Invalid response")];
return;
}
uploadKey = [uploadKey stringByAppendingPathExtension:fileExtension]; uploadKey = [uploadKey stringByAppendingPathExtension:fileExtension];
NSMutableDictionary *updatedFields = [fields mutableCopy]; NSMutableDictionary *updatedFields = [fields mutableCopy];
updatedFields[@"key"] = uploadKey; updatedFields[@"key"] = uploadKey;
[weakSelf uploadFileWithUploadUrl:uploadUrl fields:updatedFields uploadKey:uploadKey]; [strongSelf uploadFileWithUploadUrl:uploadUrl fields:updatedFields uploadKey:uploadKey];
} }
failure:^(NSURLSessionDataTask *_Nullable task, NSError *error) { failure:^(NSURLSessionDataTask *_Nullable task, NSError *error) {
DDLogError(@"%@ failed: %@", weakSelf.logTag, urlString); DDLogError(@"%@ failed: %@", weakSelf.logTag, urlString);

Loading…
Cancel
Save