[mutter] wayland/xdg-shell: Add parent window validation in get_popup()



commit 034c6ab9db2793ad8f8a5f04d46af174c04c9fa0
Author: Robert Mader <robert mader posteo de>
Date:   Sun Aug 16 22:54:23 2020 +0200

    wayland/xdg-shell: Add parent window validation in get_popup()
    
    Like in most similar places we can not assume to get a valid window
    when calling `meta_wayland_surface_get_window` as it e.g. might be
    unmapped already.
    
    Calling `get_popup` on an unmapped window is a client bug, thus post
    a protocol error when this happens.
    
    Closes https://gitlab.gnome.org/GNOME/mutter/-/issues/1174
    Closes https://gitlab.gnome.org/GNOME/mutter/-/issues/1293

 src/wayland/meta-wayland-xdg-shell.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/src/wayland/meta-wayland-xdg-shell.c b/src/wayland/meta-wayland-xdg-shell.c
index 873c8025b6..c5bdae14d4 100644
--- a/src/wayland/meta-wayland-xdg-shell.c
+++ b/src/wayland/meta-wayland-xdg-shell.c
@@ -1872,6 +1872,15 @@ xdg_surface_constructor_get_popup (struct wl_client   *client,
       return;
     }
 
+  parent_window = meta_wayland_surface_get_window (parent_surface);
+  if (!parent_window)
+    {
+      wl_resource_post_error (xdg_wm_base_resource,
+                              XDG_WM_BASE_ERROR_INVALID_POPUP_PARENT,
+                              "Invalid popup parent window");
+      return;
+    }
+
   xdg_popup = META_WAYLAND_XDG_POPUP (surface->role);
 
   xdg_popup->resource = wl_resource_create (client,
@@ -1886,8 +1895,6 @@ xdg_surface_constructor_get_popup (struct wl_client   *client,
   xdg_surface = META_WAYLAND_XDG_SURFACE (xdg_popup);
   meta_wayland_xdg_surface_constructor_finalize (constructor, xdg_surface);
 
-  parent_window = meta_wayland_surface_get_window (parent_surface);
-
   xdg_positioner = wl_resource_get_user_data (positioner_resource);
   xdg_popup->setup.placement_rule =
     meta_wayland_xdg_positioner_to_placement (xdg_positioner, parent_window);


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