From 0c41cbc85c06de7760b4198b96a9fc3a785befed Mon Sep 17 00:00:00 2001 From: manuroe Date: Wed, 27 May 2020 08:39:34 +0200 Subject: [PATCH 1/2] MXSecretShareManager: Fix crash in cancelRequestWithRequestId vector-im/riot-ios/issues/3272 --- CHANGES.rst | 3 +++ MatrixSDK/Crypto/CrossSigning/MXCrossSigning.m | 14 ++++++++++---- .../KeySharing/Secret/MXSecretShareManager.m | 13 +++++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index d3d53c2213..137069f7c8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,6 +3,9 @@ Changes in Matrix iOS SDK in 0.16.6 (2020-05-xx) Improvements: +Bug fix: + * MXSecretShareManager: Fix crash in cancelRequestWithRequestId (vector-im/riot-ios/issues/3272). + Changes in Matrix iOS SDK in 0.16.5 (2020-05-18) ================================================ diff --git a/MatrixSDK/Crypto/CrossSigning/MXCrossSigning.m b/MatrixSDK/Crypto/CrossSigning/MXCrossSigning.m index 148ce1df32..828258d314 100644 --- a/MatrixSDK/Crypto/CrossSigning/MXCrossSigning.m +++ b/MatrixSDK/Crypto/CrossSigning/MXCrossSigning.m @@ -307,8 +307,11 @@ - (void)requestPrivateKeysToDeviceIds:(nullable NSArray*)deviceIds return isSecretValid; } failure:^(NSError * _Nonnull error) { // Cancel the other request - [self.crypto.secretShareManager cancelRequestWithRequestId:sskRequestId success:^{} failure:^(NSError * _Nonnull error) { - }]; + if (sskRequestId) + { + [self.crypto.secretShareManager cancelRequestWithRequestId:sskRequestId success:^{} failure:^(NSError * _Nonnull error) { + }]; + } failure(error); }]; @@ -340,8 +343,11 @@ - (void)requestPrivateKeysToDeviceIds:(nullable NSArray*)deviceIds return isSecretValid; } failure:^(NSError * _Nonnull error) { // Cancel the other request - [self.crypto.secretShareManager cancelRequestWithRequestId:uskRequestId success:^{} failure:^(NSError * _Nonnull error) { - }]; + if (uskRequestId) + { + [self.crypto.secretShareManager cancelRequestWithRequestId:uskRequestId success:^{} failure:^(NSError * _Nonnull error) { + }]; + } failure(error); }]; diff --git a/MatrixSDK/Crypto/KeySharing/Secret/MXSecretShareManager.m b/MatrixSDK/Crypto/KeySharing/Secret/MXSecretShareManager.m index 5a921d4883..1358dcf28d 100644 --- a/MatrixSDK/Crypto/KeySharing/Secret/MXSecretShareManager.m +++ b/MatrixSDK/Crypto/KeySharing/Secret/MXSecretShareManager.m @@ -108,6 +108,13 @@ - (MXHTTPOperation *)cancelRequestWithRequestId:(NSString*)requestId { NSLog(@"[MXSecretShareManager] cancelRequestWithRequestId: %@", requestId); + // Sanity check + if (!requestId) + { + NSLog(@"[MXSecretShareManager] cancelRequestWithRequestId: Nil request id"); + failure(nil); + } + // Create an empty operation that will be mutated later MXHTTPOperation *operation = [[MXHTTPOperation alloc] init]; @@ -118,8 +125,10 @@ - (MXHTTPOperation *)cancelRequestWithRequestId:(NSString*)requestId MXPendingSecretShareRequest *pendingRequest = self->pendingSecretShareRequests[requestId]; if (!pendingRequest) { - NSLog(@"[MXSecretShareManager] cancelRequestWithRequestId: Unknown request: %@", requestId); - failure(nil); + dispatch_async(dispatch_get_main_queue(), ^{ + NSLog(@"[MXSecretShareManager] cancelRequestWithRequestId: Unknown request: %@", requestId); + failure(nil); + }); } [self->pendingSecretShareRequests removeObjectForKey:requestId]; From 04b4d58cca3c062b5198320e4677ce1b3c0473fd Mon Sep 17 00:00:00 2001 From: manuroe Date: Wed, 27 May 2020 09:44:59 +0200 Subject: [PATCH 2/2] MXIdentityService: Fix crash in handleHTTPClientError vector-im/riot-ios/issues/3273 --- CHANGES.rst | 1 + MatrixSDK/IdentityServer/MXIdentityService.m | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 137069f7c8..bf8cbb8c1f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,7 @@ Improvements: Bug fix: * MXSecretShareManager: Fix crash in cancelRequestWithRequestId (vector-im/riot-ios/issues/3272). + * MXIdentityService: Fix crash in handleHTTPClientError (vector-im/riot-ios/issues/3273). Changes in Matrix iOS SDK in 0.16.5 (2020-05-18) ================================================ diff --git a/MatrixSDK/IdentityServer/MXIdentityService.m b/MatrixSDK/IdentityServer/MXIdentityService.m index 56cff6c978..29463c682a 100644 --- a/MatrixSDK/IdentityServer/MXIdentityService.m +++ b/MatrixSDK/IdentityServer/MXIdentityService.m @@ -454,6 +454,7 @@ - (void)handleHTTPClientError:(NSNotification*)nofitication NSString *accessToken = self.restClient.accessToken; if (httpClient + && self.identityServer && [httpClient.baseURL.absoluteString hasPrefix:self.identityServer] && [mxError.errcode isEqualToString:kMXErrCodeStringTermsNotSigned] && accessToken) {