From 432ce4caa44e131e25285f2af4cb1ce120024517 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 1 Jul 2020 14:16:36 +0400 Subject: [PATCH] Fix crash in migration with corrupted settings. --- Telegram/SourceFiles/storage/localstorage.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index f5b3133bbc..8f3e7d9c9a 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -384,7 +384,7 @@ void start() { EncryptedDescriptor settings; if (!DecryptLocal(settings, settingsEncrypted, SettingsKey)) { - LOG(("App Error: could not decrypt settings from settings file, maybe bad passcode...")); + LOG(("App Error: could not decrypt settings from settings file...")); return writeSettings(); } @@ -422,7 +422,12 @@ void start() { void writeSettings() { if (!_settingsWriteAllowed) { _settingsRewriteNeeded = true; - return; + + // We need to generate SettingsKey anyway, + // for the moveLegacyBackground to work. + if (SettingsKey) { + return; + } } if (_basePath.isEmpty()) { LOG(("App Error: _basePath is empty in writeSettings()")); @@ -442,6 +447,11 @@ void writeSettings() { } settings.writeData(_settingsSalt); + if (!_settingsWriteAllowed) { + EncryptedDescriptor data(0); + settings.writeEncrypted(data, SettingsKey); + return; + } const auto configSerialized = LookupFallbackConfig().serialize(); const auto applicationSettings = Core::App().settings().serialize();