git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commit7e77ae0cf077e97401ec1454279b9546af668c53
parent7e2db7c5e7
authorIsaac Freund <[email protected]>
date2024-05-15 09:48
Server: fix filtering of newly created globals

Fixes: https://codeberg.org/river/river/issues/1068

 river/Server.zig | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/river/Server.zig b/river/Server.zig
index e1fda5f..895f1cc 100644
--- a/river/Server.zig
+++ b/river/Server.zig
@@ -289,21 +289,17 @@ fn allowlist(server: *Server, global: *const wl.Global) bool {
     if (server.drm) |drm| if (global == drm.global) return true;
     if (server.linux_dmabuf) |linux_dmabuf| if (global == linux_dmabuf.global) return true;
 
-    {
-        var it = server.root.all_outputs.iterator(.forward);
-        while (it.next()) |output| {
-            if (global == output.wlr_output.global) return true;
-        }
-    }
-
-    {
-        var it = server.input_manager.seats.first;
-        while (it) |node| : (it = node.next) {
-            if (global == node.data.wlr_seat.global) return true;
-        }
-    }
-
-    return global == hackGlobal(server.shm) or
+    // We must use the getInterface() approach for dynamically created globals
+    // such as wl_output and wl_seat since the wl_global_create() function will
+    // advertise the global to clients and invoke this filter before returning
+    // the new global pointer.
+    //
+    // For other globals I like the current pointer comparison approach as it
+    // should catch river accidentally exposing multiple copies of e.g. wl_shm
+    // with an assertion failure.
+    return global.getInterface() == wl.Output.getInterface() or
+        global.getInterface() == wl.Seat.getInterface() or
+        global == hackGlobal(server.shm) or
         global == hackGlobal(server.single_pixel_buffer_manager) or
         global == server.viewporter.global or
         global == server.fractional_scale_manager.global or