From d2c2bf5a13bbaedd0f8c6ea8af227dffe95bdb40 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Sat, 20 Nov 2021 10:48:09 -0600 Subject: wayland: fix a potential segfault on surface enter This possibility actually existed for years. The wayland protocol is asynchronous and there's no restriction on when a compositor can send a surface enter event. In mpv's case, the surface enter event is used to set some vital things regarded geometry/scaling etc. However, this implictly assumes that wl->current_output is actually initialized. The vast majority of the time, vo_wayland_reconfig will happen first which is where wl->current_output is, and should, be created. There's no rule/law that the ordering of events will always occur in this order. Plasma with certain auto-profile conditions can send the surface enter event before mpv does its initial reconfig. That segfaults of course. Just add a check to make sure we have wl->current_output here and return if we don't. This assumes that the compositor will send us another surface enterance event when mpv actually does the initial surface commit and roundtrip request later. Wayland logs indicate this does happen. Fixes #9492. --- video/out/wayland_common.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 413e26bbb5..62f471210b 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -681,6 +681,9 @@ static void surface_handle_enter(void *data, struct wl_surface *wl_surface, struct wl_output *output) { struct vo_wayland_state *wl = data; + if (!wl->current_output) + return; + struct mp_rect old_output_geometry = wl->current_output->geometry; struct mp_rect old_geometry = wl->geometry; wl->current_output = NULL; -- cgit v1.2.3