From 371da8d39423dad6dab774a39fefe895239c7e16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 6 Jul 2022 17:55:46 +0200 Subject: [PATCH] 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: --- 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 9f8a9a70f..30de94e99 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