Skip to content

Commit

Permalink
Fix mutation on iteration bug
Browse files Browse the repository at this point in the history
When MLFiletransfer adds a reconnect handler for hardlinking files on
mainapp start while another thread (the receive queue) collects the
current state to be written to db, the NSArray containing the reconnect
handlers will be mutated while the used NSKeyedArchiver tries to
serialize it.

We fix this by adding only a copy of the array in our state dictionary.
Potential other mutations are now guarded by copies, too.
  • Loading branch information
tmolitor-stud-tu committed Nov 26, 2023
1 parent 37ff940 commit dcd9247
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions Monal/Classes/MLMucProcessor.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ -(NSDictionary*) getInternalState
@synchronized(_stateLockObject) {
NSDictionary* state = @{
@"version": CURRENT_MUC_STATE_VERSION,
@"roomFeatures": _roomFeatures,
@"joining": _joining,
@"firstJoin": _firstJoin,
@"lastPing": _lastPing,
@"noUpdateBookmarks": _noUpdateBookmarks,
@"roomFeatures": [_roomFeatures copy],
@"joining": [_joining copy],
@"firstJoin": [_firstJoin copy],
@"lastPing": _lastPing copy,
@"noUpdateBookmarks": [_noUpdateBookmarks copy],
@"hasFetchedBookmarks": @(_hasFetchedBookmarks),
};
//DDLogVerbose(@"Returning MUC state: %@", state);
Expand Down
6 changes: 3 additions & 3 deletions Monal/Classes/xmpp.m
Original file line number Diff line number Diff line change
Expand Up @@ -3344,7 +3344,7 @@ -(void) realPersistState
[values setObject:persistentIqHandlers forKey:@"iqHandlers"];

@synchronized(self->_reconnectionHandlers) {
[values setObject:self->_reconnectionHandlers forKey:@"reconnectionHandlers"];
[values setObject:[self->_reconnectionHandlers copy] forKey:@"reconnectionHandlers"];
}

[values setValue:[self.connectionProperties.serverFeatures copy] forKey:@"serverFeatures"];
Expand All @@ -3355,8 +3355,8 @@ -(void) realPersistState

[values setObject:[self.pubsub getInternalData] forKey:@"pubsubData"];
[values setObject:[self.mucProcessor getInternalState] forKey:@"mucState"];
[values setObject:self->_runningCapsQueries forKey:@"runningCapsQueries"];
[values setObject:self->_runningMamQueries forKey:@"runningMamQueries"];
[values setObject:[self->_runningCapsQueries copy] forKey:@"runningCapsQueries"];
[values setObject:[self->_runningMamQueries copy] forKey:@"runningMamQueries"];
[values setObject:[NSNumber numberWithBool:self->_loggedInOnce] forKey:@"loggedInOnce"];
[values setObject:[NSNumber numberWithBool:self.connectionProperties.usingCarbons2] forKey:@"usingCarbons2"];
[values setObject:[NSNumber numberWithBool:self.connectionProperties.supportsBookmarksCompat] forKey:@"supportsBookmarksCompat"];
Expand Down

0 comments on commit dcd9247

Please sign in to comment.