Don't crash when messaging user with malformed profile

// FREEBIE
This commit is contained in:
Michael Kirk 2017-07-24 10:35:18 -04:00
parent a5f067936c
commit 6e19c1aae8
3 changed files with 25 additions and 13 deletions

View File

@ -1212,8 +1212,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
{
if (![storage containsSession:identifier deviceId:[deviceNumber intValue]]) {
__block dispatch_semaphore_t sema = dispatch_semaphore_create(0);
__block PreKeyBundle *bundle;
__block NSException *exception;
__block PreKeyBundle *_Nullable bundle;
__block NSException *_Nullable exception;
[self.networkManager makeRequest:[[TSRecipientPrekeyRequest alloc] initWithRecipient:identifier
deviceId:[deviceNumber stringValue]]
success:^(NSURLSessionDataTask *task, id responseObject) {

View File

@ -1,15 +1,15 @@
//
// PreKeyBundle+jsonDict.h
// Signal
//
// Created by Frederic Jacobs on 26/11/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "PreKeyBundle.h"
NS_ASSUME_NONNULL_BEGIN
@interface PreKeyBundle (jsonDict)
+ (PreKeyBundle *)preKeyBundleFromDictionary:(NSDictionary *)dictionary forDeviceNumber:(NSNumber *)number;
+ (nullable PreKeyBundle *)preKeyBundleFromDictionary:(NSDictionary *)dictionary forDeviceNumber:(NSNumber *)number;
@end
NS_ASSUME_NONNULL_END

View File

@ -5,17 +5,27 @@
#import "NSData+Base64.h"
#import "PreKeyBundle+jsonDict.h"
NS_ASSUME_NONNULL_BEGIN
@implementation PreKeyBundle (jsonDict)
+ (PreKeyBundle *)preKeyBundleFromDictionary:(NSDictionary *)dictionary forDeviceNumber:(NSNumber *)number {
+ (nullable PreKeyBundle *)preKeyBundleFromDictionary:(NSDictionary *)dictionary forDeviceNumber:(NSNumber *)number
{
PreKeyBundle *bundle = nil;
NSString *identityKeyString = [dictionary objectForKey:@"identityKey"];
NSArray *devicesArray = [dictionary objectForKey:@"devices"];
if (!(identityKeyString && [devicesArray isKindOfClass:[NSArray class]])) {
DDLogError(@"Failed to get identity key or messages array from server request");
id identityKeyObject = [dictionary objectForKey:@"identityKey"];
if (![identityKeyObject isKindOfClass:[NSString class]]) {
OWSFail(@"Unexpected identityKeyObject: %@", identityKeyObject);
return nil;
}
NSString *identityKeyString = (NSString *)identityKeyObject;
id devicesObject = [dictionary objectForKey:@"devices"];
if (![devicesObject isKindOfClass:[NSArray class]]) {
OWSFail(@"Unexpected devicesObject: %@", devicesObject);
return nil;
}
NSArray *devicesArray = (NSArray *)devicesObject;
NSData *identityKey = [NSData dataFromBase64StringNoPadding:identityKeyString];
@ -108,3 +118,5 @@
}
@end
NS_ASSUME_NONNULL_END