22c471
From 7bdd1962213a37f6218fe15ea1a4062dd318672a Mon Sep 17 00:00:00 2001
22c471
From: Will Thompson <wjt@endlessm.com>
22c471
Date: Wed, 28 Aug 2019 15:39:44 +0100
22c471
Subject: [PATCH 1/2] global: Don't trust persistent/runtime state data
22c471
22c471
An Endless OS system was found in the wild with a malformed
22c471
.local/share/gnome-shell/notifications. When deserialized in Python,
22c471
after passing trusted=True to g_variant_new_from_bytes(), the first
22c471
element of the first struct in the array looks like this:
22c471
22c471
    In [41]: _38.get_child_value(0).get_child_value(0)
22c471
    Out[41]: GLib.Variant('s', '\Uffffffff\Uffffffff\Uffffffff\Uffffffff\Uffffffff')
22c471
22c471
When deserialised in GJS, we get:
22c471
22c471
    gjs> v.get_child_value(0).get_child_value(0)
22c471
    [object variant of type "s"]
22c471
    gjs> v.get_child_value(0).get_child_value(0).get_string()
22c471
    typein:43:1 malformed UTF-8 character sequence at offset 0
22c471
      @typein:43:1
22c471
      @<stdin>:1:34
22c471
22c471
While g_variant_new_from_bytes() doesn't have much to say about its
22c471
'trusted' parameter, g_variant_new_from_data() does:
22c471
22c471
> If data is trusted to be serialised data in normal form then trusted
22c471
> should be TRUE. This applies to serialised data created within this
22c471
> process or read from a trusted location on the disk (such as a file
22c471
> installed in /usr/lib alongside your application). You should set
22c471
> trusted to FALSE if data is read from the network, a file in the
22c471
> user's home directory, etc.
22c471
22c471
Persistent state is read from the user's home directory, so it should
22c471
not be trusted. With trusted=False, the string value above comes out as
22c471
"".
22c471
22c471
I don't have an explanation for how this file ended up being malformed.
22c471
I also don't have an explanation for when this started crashing: my
22c471
guess is that recent GJS became stricter about validating UTF-8 but I
22c471
could be wrong!
22c471
22c471
https://gitlab.gnome.org/GNOME/gnome-shell/issues/1552
22c471
---
22c471
 src/shell-global.c | 2 +-
22c471
 1 file changed, 1 insertion(+), 1 deletion(-)
22c471
22c471
diff --git a/src/shell-global.c b/src/shell-global.c
22c471
index 4b33778e0..33046f614 100644
22c471
--- a/src/shell-global.c
22c471
+++ b/src/shell-global.c
22c471
@@ -1707,7 +1707,7 @@ load_variant (GFile      *dir,
22c471
   else
22c471
     {
22c471
       GBytes *bytes = g_mapped_file_get_bytes (mfile);
22c471
-      res = g_variant_new_from_bytes (G_VARIANT_TYPE (property_type), bytes, TRUE);
22c471
+      res = g_variant_new_from_bytes (G_VARIANT_TYPE (property_type), bytes, FALSE);
22c471
       g_bytes_unref (bytes);
22c471
       g_mapped_file_unref (mfile);
22c471
     }
22c471
-- 
22c471
2.35.1
22c471
22c471
22c471
From 13dcb3e4400b92a0d2f548e88b70b358240d462c Mon Sep 17 00:00:00 2001
22c471
From: Will Thompson <wjt@endlessm.com>
22c471
Date: Wed, 28 Aug 2019 15:38:03 +0100
22c471
Subject: [PATCH 2/2] notificationDaemon: Catch exceptions while loading
22c471
 notifications
22c471
22c471
An Endless OS system was found in the wild with a malformed
22c471
.local/share/gnome-shell/notifications which causes _loadNotifications()
22c471
to raise an exception. This exception was not previously handled and
22c471
bubbles all the way out to gnome_shell_plugin_start(), whereupon the
22c471
shell exit(1)s. The user could no longer log into their computer.
22c471
22c471
Handle exceptions from _loadNotifications(), log them, and attempt to
22c471
continue. Ensure that this._isLoading is set to 'false' even on error,
22c471
so that future calls to _saveNotifications() can overwrite the (corrupt)
22c471
state file.
22c471
22c471
https://gitlab.gnome.org/GNOME/gnome-shell/issues/1552
22c471
---
22c471
 js/ui/notificationDaemon.js | 42 ++++++++++++++++++++-----------------
22c471
 1 file changed, 23 insertions(+), 19 deletions(-)
22c471
22c471
diff --git a/js/ui/notificationDaemon.js b/js/ui/notificationDaemon.js
22c471
index 4bdede841..dbe673b88 100644
22c471
--- a/js/ui/notificationDaemon.js
22c471
+++ b/js/ui/notificationDaemon.js
22c471
@@ -749,29 +749,33 @@ var GtkNotificationDaemon = class GtkNotificationDaemon {
22c471
     _loadNotifications() {
22c471
         this._isLoading = true;
22c471
 
22c471
-        let value = global.get_persistent_state('a(sa(sv))', 'notifications');
22c471
-        if (value) {
22c471
-            let sources = value.deep_unpack();
22c471
-            sources.forEach(([appId, notifications]) => {
22c471
-                if (notifications.length == 0)
22c471
-                    return;
22c471
-
22c471
-                let source;
22c471
-                try {
22c471
-                    source = this._ensureAppSource(appId);
22c471
-                } catch(e) {
22c471
-                    if (e instanceof InvalidAppError)
22c471
+        try {
22c471
+            let value = global.get_persistent_state('a(sa(sv))', 'notifications');
22c471
+            if (value) {
22c471
+                let sources = value.deep_unpack();
22c471
+                sources.forEach(([appId, notifications]) => {
22c471
+                    if (notifications.length == 0)
22c471
                         return;
22c471
-                    throw e;
22c471
-                }
22c471
 
22c471
-                notifications.forEach(([notificationId, notification]) => {
22c471
-                    source.addNotification(notificationId, notification.deep_unpack(), false);
22c471
+                    let source;
22c471
+                    try {
22c471
+                        source = this._ensureAppSource(appId);
22c471
+                    } catch (e) {
22c471
+                        if (e instanceof InvalidAppError)
22c471
+                            return;
22c471
+                        throw e;
22c471
+                    }
22c471
+
22c471
+                    notifications.forEach(([notificationId, notification]) => {
22c471
+                        source.addNotification(notificationId, notification.deep_unpack(), false);
22c471
+                    });
22c471
                 });
22c471
-            });
22c471
+            }
22c471
+        } catch (e) {
22c471
+            logError(e, 'Failed to load saved notifications');
22c471
+        } finally {
22c471
+            this._isLoading = false;
22c471
         }
22c471
-
22c471
-        this._isLoading = false;
22c471
     }
22c471
 
22c471
     _saveNotifications() {
22c471
-- 
22c471
2.35.1
22c471