Skip to content

Commit

Permalink
Add safeguards against mutation of OCCore._queries during enumeration.
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-schwarz committed Jul 28, 2021
1 parent 8083bbd commit f9d7fd3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
8 changes: 7 additions & 1 deletion ownCloudSDK/Core/Connection Status/OCCore+ConnectionStatus.m
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,13 @@ - (void)updateConnectionStatus:(OCCoreConnectionStatus)newStatus withSignal:(OCC
[self queueBlock:^{ // See if we can proceed
if (self->_state == OCCoreStateRunning)
{
for (OCQuery *query in self->_queries)
NSArray *queries;
@synchronized(self->_queries)
{
queries = [self->_queries copy];
}

for (OCQuery *query in queries)
{
if (query.state == OCQueryStateContentsFromCache)
{
Expand Down
9 changes: 8 additions & 1 deletion ownCloudSDK/Core/ItemList/OCCore+ItemList.m
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,14 @@ - (void)_finalizeQueryUpdatesWithQueryResults:(NSMutableArray<OCItem *> *)queryR
}

// Update queries
for (OCQuery *query in self->_queries)
NSArray *queries;

@synchronized(self->_queries)
{
queries = [self->_queries copy];
}

for (OCQuery *query in queries)
{
NSMutableArray <OCItem *> *useQueryResults = nil;
OCItem *queryRootItem = nil;
Expand Down
8 changes: 7 additions & 1 deletion ownCloudSDK/Core/OCCore+ItemUpdates.m
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,13 @@ - (void)performUpdatesForAddedItems:(nullable NSArray<OCItem *> *)addedItems
}
};

for (OCQuery *query in self->_queries)
NSArray *queries;
@synchronized(self->_queries)
{
queries = [self->_queries copy];
}

for (OCQuery *query in queries)
{
// Protect full query results against modification (-setFullQueryResults: is protected using @synchronized(query), too)
@synchronized(query)
Expand Down
19 changes: 16 additions & 3 deletions ownCloudSDK/Core/OCCore.m
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,10 @@ - (void)startQuery:(OCCoreQuery *)coreQuery
{
// Add query to list of queries
[self queueBlock:^{
[self->_queries addObject:query];
@synchronized(self->_queries)
{
[self->_queries addObject:query];
}
}];

if (!query.isCustom)
Expand Down Expand Up @@ -889,7 +892,10 @@ - (void)stopQuery:(OCCoreQuery *)coreQuery
[query.stopAction cancel];

query.state = OCQueryStateStopped;
[self->_queries removeObject:query];
@synchronized(self->_queries)
{
[self->_queries removeObject:query];
}
}];
}

Expand Down Expand Up @@ -1101,7 +1107,14 @@ - (void)_replayChangesSinceSyncAnchor:(OCSyncAnchor)fromSyncAnchor
newSyncAnchor:syncAnchor
beforeQueryUpdates:^(dispatch_block_t _Nonnull completionHandler) {
// Find items that moved to a different path
for (OCQuery *query in self->_queries)
NSArray *queries;

@synchronized(self->_queries)
{
queries = [self->_queries copy];
}

for (OCQuery *query in queries)
{
OCCoreItemList *queryItemList;

Expand Down

0 comments on commit f9d7fd3

Please sign in to comment.