summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2019-02-11 22:55:09 +0300
committerDaniel Stone <daniels@collabora.com>2019-02-16 09:45:52 +0000
commit14ef201295724f5c9ed254979845d0a2d5988bd3 (patch)
tree365eb62f8b1fc592f0db3dae590409c7c09b40d1
parent15d3d3004b0c5344be3b3f7fa99381be392dfc4a (diff)
downloadweston-14ef201295724f5c9ed254979845d0a2d5988bd3.tar.gz
desktop-shell: don't crash if a surface disappears while grabbed
A surface can get destroyed while a shell grab is active, which can for example happen if the command running in weston-terminal exits. When a surface gets destroyed, grab->shsurf is reset to NULL by destroy_shell_grab_shsurf(), but otherwise the grab remains active and its callbacks continue to be called. Thus, dereferencing grab->shsurf in a callback without checking it for NULL first can lead to undefined behavior, including crashes. Several functions were already properly checking grab->shsurf for NULL, move_grab_motion() being one example. Others, however, were not, which is what this commit fixes. Related to https://gitlab.freedesktop.org/wayland/weston/issues/192 Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
-rw-r--r--desktop-shell/shell.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index aac23ac7..34b44753 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -3559,8 +3559,7 @@ rotate_grab_motion(struct weston_pointer_grab *grab,
container_of(grab, struct rotate_grab, base.grab);
struct weston_pointer *pointer = grab->pointer;
struct shell_surface *shsurf = rotate->base.shsurf;
- struct weston_surface *surface =
- weston_desktop_surface_get_surface(shsurf->desktop_surface);
+ struct weston_surface *surface;
float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
weston_pointer_move(pointer, event);
@@ -3568,6 +3567,8 @@ rotate_grab_motion(struct weston_pointer_grab *grab,
if (!shsurf)
return;
+ surface = weston_desktop_surface_get_surface(shsurf->desktop_surface);
+
cx = 0.5f * surface->width;
cy = 0.5f * surface->height;