Don't crash when messaging user with malformed profile

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent a5f067936c
commit 6e19c1aae8

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

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

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

Loading…
Cancel
Save