Prevent session corruption

Mutating the session is not thread safe.

// FREEBIE
pull/1/head
Michael Kirk 9 years ago
parent 9c426e0a4b
commit 03f05f217c

@ -665,7 +665,10 @@ NSString *const OWSMessageSenderInvalidDeviceException = @"InvalidDeviceExceptio
recipientId:identifier
deviceId:[deviceNumber intValue]];
@try {
[builder processPrekeyBundle:bundle];
// Mutating session state is not thread safe.
@synchronized(self) {
[builder processPrekeyBundle:bundle];
}
} @catch (NSException *exception) {
if ([exception.name isEqualToString:UntrustedIdentityKeyException]) {
@throw [NSException
@ -685,7 +688,11 @@ NSString *const OWSMessageSenderInvalidDeviceException = @"InvalidDeviceExceptio
recipientId:identifier
deviceId:[deviceNumber intValue]];
id<CipherMessage> encryptedMessage = [cipher encryptMessage:[plainText paddedMessageBody]];
// Mutating session state is not thread safe.
id<CipherMessage> encryptedMessage;
@synchronized (self) {
encryptedMessage = [cipher encryptMessage:[plainText paddedMessageBody]];
}
NSData *serializedMessage = encryptedMessage.serialized;
TSWhisperMessageType messageType = [self messageTypeForCipherMessage:encryptedMessage];

Loading…
Cancel
Save