From 4ad7ca79b73a313322233f545aaf47e84166d307 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 18 Sep 2018 16:44:31 -0400 Subject: [PATCH] Respond to CR. --- SignalServiceKit/src/Devices/OWSDevice.m | 5 +++-- SignalServiceKit/src/Devices/OWSProvisioningCipher.m | 4 ++++ .../src/Messages/Attachments/TSAttachmentPointer.m | 6 +++--- SignalServiceKit/src/Messages/OWSMessageManager.m | 2 +- SignalServiceKit/src/Util/NSData+OWS.m | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/SignalServiceKit/src/Devices/OWSDevice.m b/SignalServiceKit/src/Devices/OWSDevice.m index 7ae0eb5e3..6a9433ef4 100644 --- a/SignalServiceKit/src/Devices/OWSDevice.m +++ b/SignalServiceKit/src/Devices/OWSDevice.m @@ -117,6 +117,7 @@ NSString *const kOWSPrimaryStorage_MayHaveLinkedDevices = @"kTSStorageManager_Ma OWSDevice *device = [MTLJSONAdapter modelOfClass:[self class] fromJSONDictionary:deviceAttributes error:error]; if (device.deviceId < OWSDevicePrimaryDeviceId) { OWSFailDebug(@"Invalid device id: %lu", (unsigned long)device.deviceId); + *error = OWSErrorWithCodeDescription(OWSErrorCodeFailedToDecodeJson, @"Invalid device id."); return nil; } return device; @@ -181,7 +182,7 @@ NSString *const kOWSPrimaryStorage_MayHaveLinkedDevices = @"kTSStorageManager_Ma } *success = NO; OWSLogError(@"unable to decode date from %@", value); - *error = OWSErrorWithCodeDescription(OWSErrorCodeFailedToDecodeJson, @"Unable to decode date from %@"); + *error = OWSErrorWithCodeDescription(OWSErrorCodeFailedToDecodeJson, @"Unable to decode date from JSON."); return nil; } reverseBlock:^id(id value, BOOL *success, NSError **error) { @@ -194,7 +195,7 @@ NSString *const kOWSPrimaryStorage_MayHaveLinkedDevices = @"kTSStorageManager_Ma } } OWSLogError(@"unable to encode date from %@", value); - *error = OWSErrorWithCodeDescription(OWSErrorCodeFailedToEncodeJson, @"Unable to encode date"); + *error = OWSErrorWithCodeDescription(OWSErrorCodeFailedToEncodeJson, @"Unable to encode date to JSON."); *success = NO; return nil; }]; diff --git a/SignalServiceKit/src/Devices/OWSProvisioningCipher.m b/SignalServiceKit/src/Devices/OWSProvisioningCipher.m index 35a542193..25e6d531d 100644 --- a/SignalServiceKit/src/Devices/OWSProvisioningCipher.m +++ b/SignalServiceKit/src/Devices/OWSProvisioningCipher.m @@ -54,6 +54,10 @@ NS_ASSUME_NONNULL_BEGIN - (nullable NSData *)encrypt:(NSData *)dataToEncrypt { @try { + // Exceptions can be thrown in a number of places in encryptUnsafe, e.g.: + // + // * Curve25519's generateSharedSecretFromPublicKey. + // * [HKDFKit deriveKey]. return [self encryptUnsafe:dataToEncrypt]; } @catch (NSException *exception) { OWSFailDebug(@"exception: %@ of type: %@ with reason: %@, user info: %@.", diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachmentPointer.m b/SignalServiceKit/src/Messages/Attachments/TSAttachmentPointer.m index e25381983..b1be6f711 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachmentPointer.m +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachmentPointer.m @@ -54,15 +54,15 @@ NS_ASSUME_NONNULL_BEGIN + (nullable TSAttachmentPointer *)attachmentPointerFromProto:(SSKProtoAttachmentPointer *)attachmentProto { if (attachmentProto.id < 1) { - OWSFailDebug("Invalid attachment id."); + OWSFailDebug(@"Invalid attachment id."); return nil; } if (attachmentProto.key.length < 1) { - OWSFailDebug("Invalid attachment key."); + OWSFailDebug(@"Invalid attachment key."); return nil; } if (attachmentProto.contentType.length < 1) { - OWSFailDebug("Invalid attachment content type."); + OWSFailDebug(@"Invalid attachment content type."); return nil; } diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index 3de1a8d62..45b3ab8a4 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -1174,7 +1174,7 @@ NS_ASSUME_NONNULL_BEGIN } case SSKProtoGroupContextTypeQuit: { if (!oldGroupThread) { - OWSFailDebug(@"ignoring quit group message from unknown group."); + OWSLogWarn(@"ignoring quit group message from unknown group."); return nil; } [newMemberIds removeObject:envelope.source]; diff --git a/SignalServiceKit/src/Util/NSData+OWS.m b/SignalServiceKit/src/Util/NSData+OWS.m index acc78b4d7..2a39f91a8 100644 --- a/SignalServiceKit/src/Util/NSData+OWS.m +++ b/SignalServiceKit/src/Util/NSData+OWS.m @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN for (NSData *data in datas) { [result appendData:data]; } - return result; + return [result copy]; } - (NSData *)dataByAppendingData:(NSData *)data