diff --git a/CHANGELOG.md b/CHANGELOG.md index 90e368da8bf..48903ead425 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Fixed * ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?) * CompensatingWriteErrorInfo reported string primary keys as boolean values instead ([PR #5938](https://github.com/realm/realm-core/pull/5938), since the introduction of CompensatingWriteErrorInfo in 12.1.0). +* Fix a use-after-free if the last external reference to an encrypted Realm was closed between when a client reset error was received and when the download of the new Realm began. ([PR #5949](https://github.com/realm/realm-core/pull/5949), since 12.4.0). ### Breaking changes * Rename RealmConfig::automatic_handle_backlicks_in_migrations to RealmConfig::automatically_handle_backlinks_in_migrations ([PR #5897](https://github.com/realm/realm-core/pull/5897)). diff --git a/src/realm/object-store/sync/sync_session.cpp b/src/realm/object-store/sync/sync_session.cpp index 4c295cc525d..7f47d15f009 100644 --- a/src/realm/object-store/sync/sync_session.cpp +++ b/src/realm/object-store/sync/sync_session.cpp @@ -335,10 +335,18 @@ void SyncSession::download_fresh_realm(sync::ProtocolErrorInfo::Action server_re server_requests_action); } } + + std::vector encryption_key; + { + util::CheckedLockGuard lock(m_config_mutex); + encryption_key = m_config.encryption_key; + } + DBOptions options; - options.encryption_key = m_db->get_encryption_key(); options.allow_file_format_upgrade = false; options.enable_async_writes = false; + if (!encryption_key.empty()) + options.encryption_key = encryption_key.data(); std::shared_ptr db; auto fresh_path = ClientResetOperation::get_fresh_path_for(m_db->get_path());