Skip to content

Commit 7b6c8b2

Browse files
davbeckflovilmart
authored andcommitted
Fix race condition related to keychain conversion (#1353)
Fixes #1352 Because `_dataForKey` now does a conversion of the keychain item, it is no longer safe to call it concurrently. This means that all uses of `_synchronizationQueue` need to be serial, so converting it to a serial queue and removing the barrier calls works better.
1 parent 067ede1 commit 7b6c8b2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Parse/Parse/Internal/PFKeychainStore.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ - (instancetype)initWithService:(NSString *)service {
6060
_keychainQueryTemplate = [[self class] _keychainQueryTemplateForService:service];
6161

6262
NSString *queueLabel = [NSString stringWithFormat:@"com.parse.keychain.%@", service];
63-
_synchronizationQueue = dispatch_queue_create(queueLabel.UTF8String, DISPATCH_QUEUE_CONCURRENT);
63+
_synchronizationQueue = dispatch_queue_create(queueLabel.UTF8String, DISPATCH_QUEUE_SERIAL);
6464
PFMarkDispatchQueue(_synchronizationQueue);
6565

6666
return self;
@@ -166,7 +166,7 @@ - (BOOL)setObject:(id)object forKey:(NSString *)key {
166166
NSDictionary *update = @{ (__bridge NSString *)kSecValueData : data };
167167

168168
__block OSStatus status = errSecSuccess;
169-
dispatch_barrier_sync(_synchronizationQueue,^{
169+
dispatch_sync(_synchronizationQueue,^{
170170
if ([self _dataForKey:key]) {
171171
status = SecItemUpdate((__bridge CFDictionaryRef)query, (__bridge CFDictionaryRef)update);
172172
} else {
@@ -189,7 +189,7 @@ - (BOOL)setObject:(id)object forKeyedSubscript:(NSString *)key {
189189

190190
- (BOOL)removeObjectForKey:(NSString *)key {
191191
__block BOOL value = NO;
192-
dispatch_barrier_sync(_synchronizationQueue, ^{
192+
dispatch_sync(_synchronizationQueue, ^{
193193
value = [self _removeObjectForKey:key];
194194
});
195195
return value;
@@ -210,7 +210,7 @@ - (BOOL)removeAllObjects {
210210
query[(__bridge id)kSecMatchLimit] = (__bridge id)kSecMatchLimitAll;
211211

212212
__block BOOL value = YES;
213-
dispatch_barrier_sync(_synchronizationQueue, ^{
213+
dispatch_sync(_synchronizationQueue, ^{
214214
CFArrayRef result = NULL;
215215
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, (CFTypeRef *)&result);
216216
if (status != errSecSuccess) {

0 commit comments

Comments
 (0)