From c1a0b88232d88a27e7bf5b12d62fef05ffaf23ed Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 26 Aug 2016 10:01:53 -0400 Subject: [PATCH] Don't crash when contact lookup is given nil contact // FREEBIE --- src/Contacts/ContactsUpdater.m | 15 +++++++++------ src/Messages/TSMessagesManager+sendMessages.m | 2 ++ src/Util/OWSError.h | 9 +++++++++ src/Util/OWSError.m | 16 ++++++++++++++++ 4 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 src/Util/OWSError.h create mode 100644 src/Util/OWSError.m diff --git a/src/Contacts/ContactsUpdater.m b/src/Contacts/ContactsUpdater.m index 9a2cca881..61168eafc 100644 --- a/src/Contacts/ContactsUpdater.m +++ b/src/Contacts/ContactsUpdater.m @@ -1,16 +1,12 @@ -// -// ContactsManager+updater.m -// Signal -// // Created by Frederic Jacobs on 21/11/15. // Copyright © 2015 Open Whisper Systems. All rights reserved. -// #import "ContactsUpdater.h" #import "Contact.h" #import "Cryptography.h" #import "PhoneNumber.h" +#import "OWSError.h" #import "TSContactsIntersectionRequest.h" #import "TSNetworkManager.h" #import "TSStorageManager.h" @@ -63,7 +59,14 @@ - (void)lookupIdentifier:(NSString *)identifier success:(void (^)(NSSet *matchedIds))success - failure:(void (^)(NSError *error))failure { + failure:(void (^)(NSError *error))failure +{ + if(!identifier) { + NSError *error = OWSErrorWithCodeDescription(1, @"Cannot lookup nil identifier"); + BLOCK_SAFE_RUN(failure, error); + return; + } + [self contactIntersectionWithSet:[NSSet setWithObject:identifier] success:^(NSSet *matchedIds) { BLOCK_SAFE_RUN(success, matchedIds); diff --git a/src/Messages/TSMessagesManager+sendMessages.m b/src/Messages/TSMessagesManager+sendMessages.m index 740f1300c..311d11d33 100644 --- a/src/Messages/TSMessagesManager+sendMessages.m +++ b/src/Messages/TSMessagesManager+sendMessages.m @@ -139,9 +139,11 @@ dispatch_queue_t sendingQueue() { } failure:^(NSError *error) { if (error.code == NOTFOUND_ERROR) { + DDLogWarn(@"recipient contact not found with error: %@", error); [self unregisteredRecipient:recipient message:message inThread:thread]; return; } else { + DDLogError(@"contact lookup failed with error: %@", error); [self saveMessage:message withState:TSOutgoingMessageStateUnsent]; return; } diff --git a/src/Util/OWSError.h b/src/Util/OWSError.h new file mode 100644 index 000000000..500867b4b --- /dev/null +++ b/src/Util/OWSError.h @@ -0,0 +1,9 @@ +// Copyright © 2016 Open Whisper Systems. All rights reserved. + +NS_ASSUME_NONNULL_BEGIN + +extern NSString *const OWSSignalServiceKitErrorDomain; + +extern NSError *OWSErrorWithCodeDescription(NSInteger code, NSString *description); + +NS_ASSUME_NONNULL_END diff --git a/src/Util/OWSError.m b/src/Util/OWSError.m new file mode 100644 index 000000000..b35f82b12 --- /dev/null +++ b/src/Util/OWSError.m @@ -0,0 +1,16 @@ +// Copyright © 2016 Open Whisper Systems. All rights reserved. + +#import "OWSError.h" + +NS_ASSUME_NONNULL_BEGIN + +NSString *const OWSSignalServiceKitErrorDomain = @"OWSSignalServiceKitErrorDomain"; + +NSError *OWSErrorWithCodeDescription(NSInteger code, NSString *description) +{ + return [NSError errorWithDomain:OWSSignalServiceKitErrorDomain + code:code + userInfo:@{ NSLocalizedDescriptionKey: description }]; +} + +NS_ASSUME_NONNULL_END