[gnome-shell/gnome-42] signalTracker: Correctly guard against invalid GObject.ConnectFlags



commit 4852fc0df1822a45b0793450f57a88e4bcf711db
Author: Marco Trevisan (Treviño) <mail 3v1n0 net>
Date:   Wed Jul 6 17:55:46 2022 +0200

    signalTracker: Correctly guard against invalid GObject.ConnectFlags
    
    We considered any ConnectFlag value major than SWAPPED as invalid, while
    it's technically not fully true as we need to ensure that the passed
    value is respecting the whole flags mask.
    In fact, per se SWAPPED|AFTER (> SWAPPED) is a valid value (even if we
    don't support the AFTER value).
    
    But this makes the check more future-proof.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2366>
    (cherry picked from commit 371da8d39423dad6dab774a39fefe895239c7e16)

 js/misc/signalTracker.js | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/js/misc/signalTracker.js b/js/misc/signalTracker.js
index b2101122dc..3e03df4748 100644
--- a/js/misc/signalTracker.js
+++ b/js/misc/signalTracker.js
@@ -184,16 +184,18 @@ function connectObject(thisObj, ...args) {
             return [signalName, handler, 0, arg, ...rest];
 
         const flags = arg;
-        if (flags > GObject.ConnectFlags.SWAPPED)
+        let flagsMask = 0;
+        Object.values(GObject.ConnectFlags).forEach(v => (flagsMask |= v));
+        if (!(flags & flagsMask))
             throw new Error(`Invalid flag value ${flags}`);
-        if (flags === GObject.ConnectFlags.SWAPPED)
+        if (flags & GObject.ConnectFlags.SWAPPED)
             throw new Error('Swapped signals are not supported');
         return [signalName, handler, flags, ...rest];
     };
 
     const connectSignal = (emitter, signalName, handler, flags) => {
         const isGObject = emitter instanceof GObject.Object;
-        const func = flags === GObject.ConnectFlags.AFTER && isGObject
+        const func = (flags & GObject.ConnectFlags.AFTER) && isGObject
             ? 'connect_after'
             : 'connect';
         const emitterProto = isGObject


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]