Don't crash when contact lookup is given nil contact

// FREEBIE
pull/1/head
Michael Kirk 9 years ago
parent 5ae2717872
commit c1a0b88232

@ -1,16 +1,12 @@
//
// ContactsManager+updater.m
// Signal
//
// Created by Frederic Jacobs on 21/11/15. // Created by Frederic Jacobs on 21/11/15.
// Copyright © 2015 Open Whisper Systems. All rights reserved. // Copyright © 2015 Open Whisper Systems. All rights reserved.
//
#import "ContactsUpdater.h" #import "ContactsUpdater.h"
#import "Contact.h" #import "Contact.h"
#import "Cryptography.h" #import "Cryptography.h"
#import "PhoneNumber.h" #import "PhoneNumber.h"
#import "OWSError.h"
#import "TSContactsIntersectionRequest.h" #import "TSContactsIntersectionRequest.h"
#import "TSNetworkManager.h" #import "TSNetworkManager.h"
#import "TSStorageManager.h" #import "TSStorageManager.h"
@ -63,7 +59,14 @@
- (void)lookupIdentifier:(NSString *)identifier - (void)lookupIdentifier:(NSString *)identifier
success:(void (^)(NSSet<NSString *> *matchedIds))success success:(void (^)(NSSet<NSString *> *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] [self contactIntersectionWithSet:[NSSet setWithObject:identifier]
success:^(NSSet<NSString *> *matchedIds) { success:^(NSSet<NSString *> *matchedIds) {
BLOCK_SAFE_RUN(success, matchedIds); BLOCK_SAFE_RUN(success, matchedIds);

@ -139,9 +139,11 @@ dispatch_queue_t sendingQueue() {
} }
failure:^(NSError *error) { failure:^(NSError *error) {
if (error.code == NOTFOUND_ERROR) { if (error.code == NOTFOUND_ERROR) {
DDLogWarn(@"recipient contact not found with error: %@", error);
[self unregisteredRecipient:recipient message:message inThread:thread]; [self unregisteredRecipient:recipient message:message inThread:thread];
return; return;
} else { } else {
DDLogError(@"contact lookup failed with error: %@", error);
[self saveMessage:message withState:TSOutgoingMessageStateUnsent]; [self saveMessage:message withState:TSOutgoingMessageStateUnsent];
return; return;
} }

@ -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

@ -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
Loading…
Cancel
Save