Blame SOURCES/0007-xwayland-Check-buffer-prior-to-attaching-it.patch

4c4b8b
From 8a07b3e391bbed0b7d8f2ed37928b362eec3beee Mon Sep 17 00:00:00 2001
4c4b8b
From: Olivier Fourdan <ofourdan@redhat.com>
4c4b8b
Date: Mon, 29 Mar 2021 15:01:15 +0200
4c4b8b
Subject: [PATCH xserver 07/27] xwayland: Check buffer prior to attaching it
4c4b8b
MIME-Version: 1.0
4c4b8b
Content-Type: text/plain; charset=UTF-8
4c4b8b
Content-Transfer-Encoding: 8bit
4c4b8b
4c4b8b
If the buffer is NULL, do not even try to attach it, and risk a Wayland
4c4b8b
protocol error which would be fatal to us.
4c4b8b
4c4b8b
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
4c4b8b
Reviewed-by: Martin Peres <martin.peres@mupuf.org>
4c4b8b
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
4c4b8b
https://gitlab.freedesktop.org/xorg/xserver/-/issues/1156
4c4b8b
(cherry picked from commit 25d2f4948f0abd39e099b8ac69b7cb1dab38a10a)
4c4b8b
---
4c4b8b
 hw/xwayland/xwayland-cursor.c  | 11 +++++++++--
4c4b8b
 hw/xwayland/xwayland-present.c |  7 ++++++-
4c4b8b
 hw/xwayland/xwayland-window.c  |  5 +++++
4c4b8b
 3 files changed, 20 insertions(+), 3 deletions(-)
4c4b8b
4c4b8b
diff --git a/hw/xwayland/xwayland-cursor.c b/hw/xwayland/xwayland-cursor.c
4c4b8b
index fac8840e6..c4457cc2a 100644
4c4b8b
--- a/hw/xwayland/xwayland-cursor.c
4c4b8b
+++ b/hw/xwayland/xwayland-cursor.c
4c4b8b
@@ -162,8 +162,15 @@ static void
4c4b8b
 xwl_cursor_attach_pixmap(struct xwl_seat *xwl_seat,
4c4b8b
                          struct xwl_cursor *xwl_cursor, PixmapPtr pixmap)
4c4b8b
 {
4c4b8b
-    wl_surface_attach(xwl_cursor->surface,
4c4b8b
-                      xwl_shm_pixmap_get_wl_buffer(pixmap), 0, 0);
4c4b8b
+    struct wl_buffer *buffer;
4c4b8b
+
4c4b8b
+    buffer = xwl_shm_pixmap_get_wl_buffer(pixmap);
4c4b8b
+    if (!buffer) {
4c4b8b
+        ErrorF("cursor: Error getting buffer\n");
4c4b8b
+        return;
4c4b8b
+    }
4c4b8b
+
4c4b8b
+    wl_surface_attach(xwl_cursor->surface, buffer, 0, 0);
4c4b8b
     xwl_surface_damage(xwl_seat->xwl_screen, xwl_cursor->surface, 0, 0,
4c4b8b
                        xwl_seat->x_cursor->bits->width,
4c4b8b
                        xwl_seat->x_cursor->bits->height);
4c4b8b
diff --git a/hw/xwayland/xwayland-present.c b/hw/xwayland/xwayland-present.c
4c4b8b
index 7ba7efc11..83d67517a 100644
4c4b8b
--- a/hw/xwayland/xwayland-present.c
4c4b8b
+++ b/hw/xwayland/xwayland-present.c
4c4b8b
@@ -443,6 +443,12 @@ xwl_present_flip(WindowPtr present_window,
4c4b8b
     if (!xwl_window)
4c4b8b
         return FALSE;
4c4b8b
 
4c4b8b
+    buffer = xwl_glamor_pixmap_get_wl_buffer(pixmap);
4c4b8b
+    if (!buffer) {
4c4b8b
+        ErrorF("present: Error getting buffer\n");
4c4b8b
+        return FALSE;
4c4b8b
+    }
4c4b8b
+
4c4b8b
     damage_box = RegionExtents(damage);
4c4b8b
 
4c4b8b
     event = malloc(sizeof *event);
4c4b8b
@@ -450,7 +456,6 @@ xwl_present_flip(WindowPtr present_window,
4c4b8b
         return FALSE;
4c4b8b
 
4c4b8b
     pixmap->refcnt++;
4c4b8b
-    buffer = xwl_glamor_pixmap_get_wl_buffer(pixmap);
4c4b8b
 
4c4b8b
     event->event_id = event_id;
4c4b8b
     event->xwl_present_window = xwl_present_window;
4c4b8b
diff --git a/hw/xwayland/xwayland-window.c b/hw/xwayland/xwayland-window.c
4c4b8b
index d0c7c581d..af4290ec7 100644
4c4b8b
--- a/hw/xwayland/xwayland-window.c
4c4b8b
+++ b/hw/xwayland/xwayland-window.c
4c4b8b
@@ -805,6 +805,11 @@ xwl_window_post_damage(struct xwl_window *xwl_window)
4c4b8b
 #endif
4c4b8b
         buffer = xwl_shm_pixmap_get_wl_buffer(pixmap);
4c4b8b
 
4c4b8b
+    if (!buffer) {
4c4b8b
+        ErrorF("Error getting buffer\n");
4c4b8b
+        return;
4c4b8b
+    }
4c4b8b
+
4c4b8b
 #ifdef XWL_HAS_GLAMOR
4c4b8b
     if (xwl_screen->glamor)
4c4b8b
         xwl_glamor_post_damage(xwl_window, pixmap, region);
4c4b8b
-- 
4c4b8b
2.31.1
4c4b8b