/
fix-return-boolean-from-safestorage-isencryptionavailable-instead-of-crashing.patch
30 lines (25 loc) · 1.79 KB
/
fix-return-boolean-from-safestorage-isencryptionavailable-instead-of-crashing.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Darshan Sen <raisinten@gmail.com>
Date: Mon, 25 Apr 2022 17:03:34 +0530
Subject: fix: return boolean from `safeStorage.isEncryptionAvailable()` instead of crashing
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this change patches [`IsEncryptionAvailable()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=245;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
to return false if the config hasn't been set already.
Fixes: https://github.com/electron/electron/issues/32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
diff --git a/os_crypt/os_crypt_linux.cc b/os_crypt/os_crypt_linux.cc
index 07da4e55f1788..2781d060bbe1d 100644
--- a/os_crypt/os_crypt_linux.cc
+++ b/os_crypt/os_crypt_linux.cc
@@ -242,7 +242,7 @@ void OSCrypt::SetConfig(std::unique_ptr<os_crypt::Config> config) {
// static
bool OSCrypt::IsEncryptionAvailable() {
- return g_get_password[Version::V11]();
+ return g_cache.Get().config && g_get_password[Version::V11]();
}
// static